-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Require explicit annotations for List[object] and Dict[*, object] #6792
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
Conversation
1923819
to
b200ed8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! The general logic looks good. I have some suggestions here
294bfb1
to
afac318
Compare
Please don't force-push and/or rebase, this makes reviewing much harder, just push more commits and merge when necessary. |
afac318
to
6cce5ad
Compare
Sorry, didn't see that until my last force push. I will stop. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updates! I have few more comments. Also you didn't implement interaction with --allow-untyped-globals
which is important, since this generates some extra errors. There is also a lint error. Finally, self-check still fails, but now the errors look more reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updates! The logic LGTM now, I only have few minor style comments.
Also after reading again, I think it makes sense to add dedicated tests (apart from fixing existing tests). Mostly to test that this is not triggered where it shouldn't, for example:
class C:
def __init__(self) -> None:
self.x = [object()]
c: C
c.x = [1, '2'] # this should be OK
Also I encourage you to add the necessary fixes in mypy code to fix self-check to this PR. This is the best way for us to double-check whether current heuristic is "smart enough".
Re: Guido's comment on the issue, should I add another option to disable this behavior to preserve some backwards compatibility? |
It may be best to first only enable this through a flag, and once we've successfully used this with a few big codebases (for example, with internal Dropbox codebases) in addition to mypy we can make this enabled by default (or always). |
Why can't we just try it with Dropbox code bases now, even before merging? Adding new flag is still some effort, so I would propose to first address existing comments, add tests, make CI build green (this may already highlight some problems in mypy self-check, as I mentioned in my review), and then I will try this PR against our internal code bases to see how well it works. |
Other test fixes still incoming |
What is the status here? This has a merge conflict and some tests still fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be fixed
Closing this in favor of #9051. (Which I'm not sure if it will get merged, but.) |
This currently breaks mypy typechecking. Including instances like
Should
seen
require explicit annotation, or presumably mypy should be smart enough to figure this out.(#3816)