Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Suggestion for empty TupleType syntax error (#9670)
* Improve Suggestion for empty TupleType syntax error The mypy syntax for a function or method that takes zero parameters is `() -> …`. Some new mypy users will reason by symmetry that the syntax for a method that returns nothing is likely `(…) -> ()`. A user who incorrectly annotates a function with `… -> ()` will be given the suggestion `Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn)`. This suggestion is unlikely to help correct the user's misconception about how to annotate the return type of a method that does not explicitly return a value. This PR adds a case to TupleType syntax error handling that returns a helpful suggestion in the case where the tuple contains zero items. Note: The error message casing in TupleType has grown large enough that it likely warrants relocation to `MessageBuilder`, but as there is not a `MessageBuilder` in accessible from `TypeAnalyzer` I have decided to add this single error case the easy way. There is a preexisting comment about the inaccessibility of `MessageBuilder` in `RypeAnalyzer`'s `cannot_resolve_type method`. I have added a test to `check-functions.test` that verifies the new suggestion is printed when `-> ()` is used as a return type annotation. I have also tested that a valid return type of `-> Tuple[()]` remains without error. * Clarify suggestion message
- Loading branch information