stubtest raises an exception when a `classmethod`'s first parameter not named `cls`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Crash Report
From https://github.com/python/typeshed/pull/10544#discussion_r1368024543
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in mypy/stubtest.py around verify_decorator, _resolve_funcitem_from_decorator, and apply_decorator_to_funcitem, following the traceback. Reproduce with the urllib3 example and run tests/stubtest_third_party.py urllib3. Done means stubtest no longer raises an exception when a runtime classmethod's first parameter is not named cls, with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100