-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Skip more method bodies in third-party libraries #19586
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
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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.
Makes sense! I'm surprised by visible selfcheck improvement, though: if there is any, maybe something is wrong, mypy doesn't have a lot of non-stub dependencies... One question (I'm not very familiar with that part, sorry it it's dumb): can this change cause any issues with PEP695 variance inference? Probably not, all self
attribute assignments should be retained here, but I'd better ask
@@ -856,6 +857,8 @@ def __init__( | |||
# the majority). In cases where self is not annotated and there are no Self | |||
# in the signature we can simply drop the first argument. | |||
self.is_trivial_self = False | |||
# Keep track of functions where self attributes are defined. | |||
self.has_self_attr_def = False |
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.
Wow, I love this. Can we use this flag later to fix overly optimistic narrowing like in #17537? (even just "this method has an explicit assignment to self
" would be better than nothing, but even tracking nested method calls should be doable)
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.
FWIW we can, but with great care (it is one thing to do something as an optimization, and another thing to do the same for correctness).
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.
Nice!
re self check: naively my guess would just be pytest
I think no. (also we are already doing this in a lot of cases, this PR simply increases the number of scenarios where we can do this) |
A while ago we started stripping function bodies when checking third-party libraries. This PR pushes this idea further:
fastparse.py
to only considerfoo.bar
as possible self attribute definition.self
attribute definitions during semantic analysis.In total this makes e.g.
mypy -c 'import torch'
~10% faster. Surprisingly, this also has some visible impact on self-check.