-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Feature proposal: an option --any-as-object to avoid false negatives #12856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
I think this is an exact duplicate of #9153. The title/wording has changed a couple of times, but the end goal has always been to ultimately treat
I think This could also mean that's it's worth having one flag that treats everything as object, and another which still warns about |
In fact it isn't. #9153 is about reducing strictness; this is about having even more of it. (as an available option for those who wish to use it, not affecting anyone else) |
Ah, from your example, I'd argue that is a bug with mypy. It doesn't consider |
Feature
Mypy would have an option to consider any occurrence of
Any
as beingobject
in order to issue a warning or error whenAny
is used as if it were any type more specific thanobject
.Related #3194
Pitch
It turned out that the typeshed will rather "err on the side of convenience" and use
Any
to avoid causing annoyance in existing codebases.This opens the door to potential type errors at run time without ever getting so much as a warning from mypy.
This option would allow to turn the problem on its head for those who wish to do so, giving an option to err on the side of caution rather than convenience — the benefit of ensuring no runtime type errors, at the cost of more hoops to jump through.
When using the WSGI protocol for example, using
--disallow-any-expr
, this ended in utter confusion due to different standards seemingly applied to my code on the one hand, and the libraries on the other:To have an error in one case and not the other was completely confusing to begin with, since in all logic, both expressions have the same type (
str
in this case). Therefore, the intuition was that they should either be both valid or both wrong.Looking further, I discovered that in the first case, I was actually not protected against a runtime type error due to
Any
: https://github.com/python/cpython/blob/main/Lib/wsgiref/types.py#L29I understand that the typeshed uses
Any
to avoid creating too many errors in existing code bases, but since I'm getting started from scratch I would actually like to get the "annoyance" over potential runtime type errors.It is for the same reason that mypy already has various 'strictness' options, for users who have an approach where they value guarantees that actually hold, more than being spared to go the final mile.
The option proposed here would elegantly convert cases with potential for false negatives to cases with potential for false positives.
Thanks to jinsun on the official #python IRC for the original concept of
Any → object
.The text was updated successfully, but these errors were encountered: