Repository navigation
Commit d21cf1b
authored
stubtest: don't crash when a classmethod's first parameter isn't named cls (#21941)
fixes #16583
the first parameter of a classmethod can be called anything . networkx
really does write
`def construct(EdgeComponentAuxGraph, G)` . stubtest checked that name
against a list of four
and raised `StubtestFailure` when it did not match :
```
StubtestFailure: unexpected class parameter name 'EdgeComponentAuxGraph' in pkg.EdgeComponentAuxGraph.construct
```
that is not a normal stubtest error , it stops the whole run , so one
oddly named parameter
takes out stub checking for a whole distribution . that is what happens
on
python/typeshed#13587 .
the name is never used for anything . the line right under it drops the
argument by position ,
so the check was not guarding the code below it . it looks at the
argument kind now instead .
while testing i found a second way onto the same line . a stub written
`def f(*args)` under
`@classmethod` also crashed . there is nothing bound to drop in that
case , and
`inspect.signature` of the runtime classmethod keeps the star argument
too , so both sides
already match and it returns unchanged . dropping it would have made a
false mismatch .
two cases added to `test_static_class_method` , one for the odd name and
one for `*args` .
both fail on master with the crash above .
`teststubtest.py` and `teststubgen.py` give 440 passed , 1 skipped , 2
xfailed . self check
on the two files is clean , and so are black and ruff .
small heads up , #21863 adds its own cases to `test_static_class_method`
starting on the same
line , so whichever goes in second will need a rebase . it is only the
test file , that one
changes `verify_var` and this one changes
`_resolve_funcitem_from_decorator` , so they do not
touch the same code .1 parent 45b9b1d commit d21cf1b
2 files changed
Lines changed: 33 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1576 | 1576 | | |
1577 | 1577 | | |
1578 | 1578 | | |
1579 | | - | |
1580 | | - | |
1581 | | - | |
1582 | | - | |
1583 | | - | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
1584 | 1583 | | |
1585 | 1584 | | |
1586 | | - | |
| 1585 | + | |
| 1586 | + | |
1587 | 1587 | | |
1588 | 1588 | | |
1589 | 1589 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
687 | 687 | | |
688 | 688 | | |
689 | 689 | | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
690 | 717 | | |
691 | 718 | | |
692 | 719 | | |
| |||
0 commit comments