stubtest: don't crash when a classmethod's first parameter isn't named cls - #21941
Open
HuzaifaChaudary wants to merge 1 commit into
Open
stubtest: don't crash when a classmethod's first parameter isn't named cls#21941HuzaifaChaudary wants to merge 1 commit into
HuzaifaChaudary wants to merge 1 commit into
Conversation
…alled cls the first parameter of a classmethod can be named anything, and networkx really does write def construct(EdgeComponentAuxGraph, G). stubtest checked the name against a list of four and raised StubtestFailure when it did not match, which aborts the whole run rather than reporting an error, so one odd name takes out stub checking for a whole distribution. the name is never used, the argument is dropped positionally on the next line, so the check guarded nothing. it looks at the argument kind instead now. a stub written def f(*args) reached the same line and crashed too. there is nothing bound to drop in that case, and inspect.signature of the runtime classmethod keeps the star argument as well, so both sides already line up and it returns unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 fourand raised
StubtestFailurewhen it did not match :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@classmethodalso crashed . there is nothing bound to drop in that case , andinspect.signatureof the runtime classmethod keeps the star argument too , so both sidesalready 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.pyandteststubgen.pygive 440 passed , 1 skipped , 2 xfailed . self checkon the two files is clean , and so are black and ruff .
small heads up , #21863 adds its own cases to
test_static_class_methodstarting on the sameline , so whichever goes in second will need a rebase . it is only the test file , that one
changes
verify_varand this one changes_resolve_funcitem_from_decorator, so they do nottouch the same code .