GeezerVison is showing github.com — stubtest raises an exception when a `classmethod`'s first parameter not named `cls` · Issue #16583 · python/mypy
stubtest raises an exception when a classmethod's first parameter not named cls #16583Description
Crash Report
From python/typeshed#10544 (comment)
Where networkx's source code has:
class EdgeComponentAuxGraph:
@classmethod
def construct(EdgeComponentAuxGraph, G): ...
Traceback
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 1891, in <module>
sys.exit(main())
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 1887, in main
return test_stubs(parse_options(sys.argv[1:]))
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 1760, in test_stubs
for error in test_module(module):
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 223, in test_module
yield from verify(stub, runtime, [module_name])
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 401, in verify_mypyfile
yield from verify(stub_entry, runtime_entry, object_path + [entry])
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 543, in verify_typeinfo
yield from verify(stub_to_verify, runtime_attr, object_path + [entry])
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 1261, in verify_decorator
func = _resolve_funcitem_from_decorator(stub)
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 1240, in _resolve_funcitem_from_decorator
resulting_func = apply_decorator_to_funcitem(decorator, func)
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 1225, in apply_decorator_to_funcitem
raise StubtestFailure(
__main__.StubtestFailure: unexpected class argument name 'EdgeComponentAuxGraph' in networkx.algorithms.connectivity.edge_kcomponents.EdgeComponentAuxGraph.construct
To Reproduce
(Write what you did to reproduce the crash. Full source code is
appreciated. We also very much appreciate it if you try to narrow the
source down to a small stand-alone example.)
From my experience, in typeshed, changing any classmethod's first parameter of a class that is present at runtime should raise the exception.
For example, in stubs/urllib3/urllib3/fields.pyi, you could change RequestField.from_tuples's cls parameter to anything else (ie: not_cls). Then run python ./tests/stubtest_third_party.py urllib3.
Your Environment
- Mypy version used: mypy 1.7.1 (compiled: yes)
- Mypy command-line flags: (see typeshed)
- Mypy configuration options from
mypy.ini (and other config files): N/A
- Python version used: 3.9.13
- Operating system and version: Windows 10 Version 10.0.19045 Build 19045
Activitychanged the title [-]stubtest crash with a classmethod's first parameter not named `cls`[/-] [+]stubtest raises an exception when a `classmethod`'s first parameter not named `cls`[/+] on Nov 28, 2023jorenham commented on Mar 5, 2025 I think this issue has been resolved in the meantime: In NumPy there are several classmethods that use subtype instead of cls, and stubtest seems to have no problem with them. Avasam commented on Mar 6, 2025 SponsorContributorAuthor More actions Still failing: python/typeshed#13587 Could be due to the parameter being named exactly like the class.
https://github.com/python/typeshed/actions/runs/13690424147/job/38282574496?pr=13587#step:5:96
Commands run:
/tmp/stubtest-e2on6yu3/bin/pip install networkx[]==3.4.2 mypy==1.15.0 numpy>=1.20 pandas
MYPYPATH=stubs/networkx /tmp/stubtest-e2on6yu3/bin/python -m mypy.stubtest --custom-typeshed-dir . --ignore-missing-stub networkx --allowlist stubs/networkx/@tests/stubtest_allowlist.txt
**********************************************************************
Command output:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/tmp/stubtest-e2on6yu3/lib/python3.12/site-packages/mypy/stubtest.py", line 2127, in <module>
sys.exit(main())
^^^^^^
File "/tmp/stubtest-e2on6yu3/lib/python3.12/site-packages/mypy/stubtest.py", line 2123, in main
return test_stubs(parse_options(sys.argv[1:]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/stubtest-e2on6yu3/lib/python3.12/site-packages/mypy/stubtest.py", line 1992, in test_stubs
for error in test_module(module):
^^^^^^^^^^^^^^^^^^^
File "/tmp/stubtest-e2on6yu3/lib/python3.12/site-packages/mypy/stubtest.py", line 248, in test_module
yield from verify(stub, runtime, [module_name])
File "/tmp/stubtest-e2on6yu3/lib/python3.12/site-packages/mypy/stubtest.py", line 426, in verify_mypyfile
yield from verify(stub_entry, runtime_entry, object_path + [entry])
File "/tmp/stubtest-e2on6yu3/lib/python3.12/site-packages/mypy/stubtest.py", line 588, in verify_typeinfo
yield from verify(stub_to_verify, runtime_attr, object_path + [entry])
File "/tmp/stubtest-e2on6yu3/lib/python3.12/site-packages/mypy/stubtest.py", line 13[68](https://github.com/python/typeshed/actions/runs/13690424147/job/38282574496?pr=13587#step:5:69), in verify_decorator
func = _resolve_funcitem_from_decorator(stub)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/stubtest-e2on6yu3/lib/python3.12/site-packages/mypy/stubtest.py", line 1334, in _resolve_funcitem_from_decorator
resulting_func = apply_decorator_to_funcitem(decorator, func)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/stubtest-e2on6yu3/lib/python3.12/site-packages/mypy/stubtest.py", line 1319, in apply_decorator_to_funcitem
raise StubtestFailure(
StubtestFailure: unexpected class argument name 'EdgeComponentAuxGraph' in networkx.algorithms.connectivity.edge_kcomponents.EdgeComponentAuxGraph.construct
**********************************************************************
Python version: Python 3.12.9 (main, Feb 5 2025, 03:22:31) [GCC 13.3.0]
Ran with the following environment:
mypy==1.15.0
mypy-extensions==1.0.0
networkx==3.4.2
numpy==2.2.3
pandas==2.2.3
pip==25.0.1
python-dateutil==2.9.0.post0
pytz==2025.1
six==1.17.0
typing_extensions==4.12.2
tzdata==2025.1Reacted by Joren Hammudoglu added a commit that references this issue on Oct 19, 2026This issue will close once commit d21cf1b is merged into the 'master' branch.d21cf1b
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|