-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[1.16 regression] Incorrect inferred type when using a classmethod from a different class as an attribute #19146
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
Thanks, I assume we have some change that is more eagerly binding self types? |
@A5rocks yeah, that'd be my guess too |
BTW @delfick are any of the repositories you are checking open source? It would be nice to get some more test cases for https://github.com/hauntsaninja/mypy_primer, which would let us catch these regressions earlier. |
Unfortunately not. I work on https://kraken.tech and my role specifically is around getting many millions of lines of python in our main monorepo to be strongly typed (which is made possible by mypy supporting plugins). Definitely not an open source repo! |
@A5rocks is there a discord/slack I can join, I'm more than happy to have a closer working relationship with mypy devs! |
There's nothing user-facing, though IMO it would be a good idea to try to extend a level of support for users (and not just Dropbox!). I'm not in a position to make anything though. Testing new releases like this is already very useful! |
fair :)
yeah, definitely. It took me 1.5 years to get us onto the latest version of mypy and I'm so happy I can finally run mypy releases ahead of them being released! I still have another 122 errors that I'm going through atm to see if I found any other regressions (this release gave me 300 new errors which is not too bad, most of them look like they're because of how mypy now understands optional Anys where it use to only think of them as Any) |
@A5rocks after a basic run through of the remaining errors I think for this repo, it's just this issue and the one I made about the match statement, which does seem like a bad regression |
cc @ilevkivskyi as the author of #18847 |
OK, this one is tricky. Mypy actually never handled bound methods correctly, if you try To understand better, try this: class Child: # NOTE: base class removed
get_actions = ActionsGetter.get_actions
reveal_type(Child().get_actions) This will show you
both in 1.15 and in 1.16. In fact, mypy follows some rules on whether a variable is a class variable or an instance variable (can't find a good docs reference on this however). And according to these rules An unrelated problem is that the error message is somewhat confusing, because it says "expression has type", while in fact we are comparing "externally visible" type of attribute on subclass vs same on superclass. So although it is technically a regression, it used to work by pure accident, and the new behavior is more consistent, i.e. uniformly broken :-). Unfortunately, a proper fix is non-trivial, it would require a new attribute on callable type, that would need to be carefully passed around everywhere (but also to be clear it is not too hard either). A possible workaround is to specify add an explicit annotation |
@ilevkivskyi right. That makes sense. Fair enough. It appears Thanks for taking a look! |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I decided to try out the new mypy 1.16 branch on the codebase I work on and I found what I think is a bug.
Let's say you have the following code (makes more sense in the concrete example it comes from)
This works at runtime but at static time it complains with
Where it believes that the type of
Child.get_actions
isCallable[[], Iterable[str]]
instead ofCallable[[Arg(str, 'event_type')], Iterable[str]]
Your Environment
mypy a.py
mypy.ini
(and other config files): no configThe text was updated successfully, but these errors were encountered: