Add more precise error message for Callable annotation#12518
Add more precise error message for Callable annotation#12518hauntsaninja merged 1 commit intopython:masterfrom
Conversation
|
What if we just remove the "or Callable" part? We should nudge people towards more precise types, and error messages don't need to include every detail. |
We could probably remove the "or Callable" part if a user has the |
|
One of my least favorite parts of typing is typing a That said, I can see an argument being made that, if you choose for the Dependent on the outcome of this discussion I will fix the flake8 error or change the error message. |
This comment has been minimized.
This comment has been minimized.
|
@frerikandriessen what flake8 error are you referring to? And note that I'm not proposing to remove the ability to write " |
The flake8 CI check is failing because one of the lines is slightly too long |
mypy/typeanal.py
Outdated
| else: | ||
| self.fail('Please use "Callable[[<parameters>], <return type>]" or "Callable"', t) | ||
| if self.options.disallow_any_generics: | ||
| self.fail('Please use "Callable[[<parameters>], <return type>]" or "Callable[..., Any]"', t) |
There was a problem hiding this comment.
| self.fail('Please use "Callable[[<parameters>], <return type>]" or "Callable[..., Any]"', t) | |
| self.fail('Please use "Callable[[<parameters>], <return type>]"', t) |
Let's remove the suboptimal suggestion here
There was a problem hiding this comment.
My 2 cents: I actually want to keep the error message with both suggestions, because the 'suboptimal' suggestion is exactly what I wanted to know. So for me it was very helpful (albeit unfortunately misleading, which is why I've corrected it). Just to emphasize that some users will get value from the not-concise message.
That said, if you still want me to remove that part I'll gladly do so.
There was a problem hiding this comment.
@JelleZijlstra just to double-check: I lined out above why I wanted to keep that message as is. Do you still want me to change it?
There was a problem hiding this comment.
I'd still lean towards removing it. Error messages should be short and provide the most useful option, and Callable[..., Any] generally isn't what we should steer people towards.
There was a problem hiding this comment.
Okay, I've incorporated your suggestion
Adds a more precise error message for a Callable annotation, if the option --disallow-any-generics has been used. The suggestion in the old message was incorrect in this scenario.
77e98b2 to
1b00107
Compare
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Description
Adds a more precise error message for a
Callableannotation, if theoption
--disallow-any-generics(part of--strictmode) has been used. The suggestion in the oldmessage was incorrect in this scenario.
Fixes #11757
Test Plan
Contents of test.py:
Results: