Commit 5186052
authored
[stubtest] Improve checking of positional-only parameters in dunder methods (#19593)
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 methods 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, so we can 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.1 parent 5d6bde6 commit 5186052
4 files changed
Lines changed: 15 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
913 | 913 | | |
914 | 914 | | |
915 | 915 | | |
916 | | - | |
| 916 | + | |
917 | 917 | | |
918 | 918 | | |
919 | 919 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
416 | 419 | | |
417 | 420 | | |
418 | 421 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1081 | 1081 | | |
1082 | 1082 | | |
1083 | 1083 | | |
1084 | | - | |
1085 | 1084 | | |
1086 | 1085 | | |
1087 | 1086 | | |
| |||
2301 | 2300 | | |
2302 | 2301 | | |
2303 | 2302 | | |
| 2303 | + | |
2304 | 2304 | | |
2305 | 2305 | | |
2306 | 2306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1724 | 1724 | | |
1725 | 1725 | | |
1726 | 1726 | | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
1727 | 1737 | | |
1728 | 1738 | | |
1729 | 1739 | | |
| |||
0 commit comments