-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[stubtest] Improve checking of positional-only parameters in dunder methods #19593
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
New typeshed stdlib hits1 (CI run):
New typeshed third-party stub hits1 (CI run):
Footnotes
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
I think this is ready for review. At this point I've gone through all of the new typeshed hits: all were true positives, and most have been corrected in typeshed. The only remaining errors are in |
Currently, mypy treats all special methods as being implicitly positional-only. This creates a blind spot for stubtest, since it means that stubtest isn't sensitive to whether special method in stub files are typed as being positional-only or not.
This PR adds an internal option to disable the positional-only-special-method heuristic when running stubtest. This way, stubtest can see the actual stub signatures as written in the stub files, making it possible to meaningfully compare them against the runtime signatures.
Now, stubtest will warn about dunder methods that are positional-only at runtime but keyword-or-positional in the stubs. Note that it still doesn't warn about the reverse (keyword-or-positional at runtime but positional-only in the stubs). The latter might be worth revisiting as well, but the typeshed hits are less obvious and there are a number of cases where this is done deliberately that would need allowlist entries.