Skip more method bodies in third-party libraries#19586
Skip more method bodies in third-party libraries#19586ilevkivskyi merged 1 commit intopython:masterfrom
Conversation
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
sterliakov
left a comment
There was a problem hiding this comment.
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
| # 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.
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.
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).
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.pyto only considerfoo.baras possible self attribute definition.selfattribute 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.