-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix binding difference between callables and callback protocols #15993
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Hm, it looks like all new errors are technically correct. NumPy stubs take into account current (inconsistent) mypy's behavior. I am not sure what is the best way forward: even if we fix the NumPy stubs, everyone who doesn't pin mypy will get errors until they update NumPy stubs, and vice versa. |
|
would it be feasible to have a per module configuration option that helps to annotate whether or not to do the check, that way one could opt-in to the new way and the numpy specs could gradually fix their types ideally this would warn in a way that helps people figure what flags to set at either definition or usage site |
|
im working around this using a Concatenate and mypy_extensions.Arg for now |
|
i thik i now understand the underlying issue its structurally incorrect to do the first parameters strop off instead its necessary to be aware of the method descriptor protocol and applying it so any callable protocol would need a and for callables its also a bug to pretend they bind, in particular when i'd like if there was a typing helper for this so one could spell Binding/nonBinding locations for those |
|
i learned that the workaround with mypy_extensions no longer works |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The relevant definitions in cc @jorenham It may be good to finally fix this little inconsistency in mypy, see (#15993 (comment) for some more details). |
|
Yea that part of the numpy stubs has been bothering me for a while now. I've made some progress in fixing those "methods" over the last year, but there's indeed still work to be done. Keep in mind that if I fix this, and I do so by the book, then it'll be in numpy 2.4, which will be released in 5 months or so. If we also take the SPEC 0 support window into account (which we should, because in general numpy users often use older versions), which means that we should add another two years to this. What I think I'll do is fix this, and if mypy_primer remains silent, then I'll try to sneak it in as a 2.3 patch release. It's a bit risky, but it'll save half a year of incorrect behavior, so it's probably worth risk. That still leaves the 2 year-long support window though... Special casing numpy also doesn't sound very attractive to me either. But I also don't want to be the reason that mypy can't proceed with this. Maybe we should wait until there is at least one numpy version where this will work correctly (i.e. ignore the support window), so that we can tell numpy users that are affected by this that they should upgrade to the latest numpy release? In the worst case, that will be 5 months, and in the best case that'll be one month. Either way, thanks for the ping; I really appreciate it :) |
|
The NumPy issues have been fixed (on main) and will be included in 2.3.4 or 2.4.0, whichever comes first. |
The 2.3.4 release is planned for this weekend |
|
@jorenham Great, thanks for the update! |
This comment has been minimized.
This comment has been minimized.
There was a bit of a delay apparently, but the 2.3.4 wheels have just been uploaded to PyPI: https://pypi.org/project/numpy/ |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Fixes #15926 (comment), fixes #16200