python / python/mypy

stubtest raises an exception when a `classmethod`'s first parameter not named `cls`

Offen
#16,583 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

crash topic-stubtest
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in mypy/stubtest.py bei verify_decorator, _resolve_funcitem_from_decorator und apply_decorator_to_funcitem und folge dem Traceback. Reproduziere das Problem mit dem urllib3-Beispiel und führe tests/stubtest_third_party.py urllib3 aus. Fertig ist die Arbeit, wenn stubtest keine Ausnahme mehr auslöst, wenn der erste Parameter eines zur Laufzeit verwendeten classmethod nicht cls heißt, und eine Regressionstestabdeckung vorhanden ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
devtools, testing-qa
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.