python / python/mypy

Stubtest crashes if an `@overload` is decorated

Offen
#20,064 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

I tried running stubtest on the numpy codebase using the compiled mypy 1.18.2 version + the patch from #20063. This triggered an assertion failure in hypothesis.extra.numpy.arrays (huh?). The relevant code contains code like

@overload
@defines_strategy(force_reusable_values=True)
def arrays(
   # --snip--

which I believe is what is triggering this asserion to fail. See HypothesisWorks/hypothesis#4564 for the relevant code.

Traceback

Traceback (most recent call last):
  File "/home/joren/Workspace/numpy/.venv/bin/stubtest", line 10, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/joren/Workspace/numpy/.venv/lib/python3.14/site-packages/mypy/stubtest.py", line 2448, in main
    return test_stubs(parse_options(sys.argv[1:]))
  File "/home/joren/Workspace/numpy/.venv/lib/python3.14/site-packages/mypy/stubtest.py", line 2296, in test_stubs
    for error in test_module(module):
                 ~~~~~~~~~~~^^^^^^^^
  File "/home/joren/Workspace/numpy/.venv/lib/python3.14/site-packages/mypy/stubtest.py", line 257, in test_module
    yield from verify(stub, runtime, [module_name])
  File "/home/joren/Workspace/numpy/.venv/lib/python3.14/site-packages/mypy/stubtest.py", line 436, in verify_mypyfile
    yield from verify(stub_entry, runtime_entry, object_path + [entry])
  File "/home/joren/Workspace/numpy/.venv/lib/python3.14/site-packages/mypy/stubtest.py", line 1347, in verify_overloadedfuncdef
    stub_sig = Signature.from_overloadedfuncdef(stub)
  File "/home/joren/Workspace/numpy/.venv/lib/python3.14/site-packages/mypy/stubtest.py", line 971, in from_overloadedfuncdef
    assert func is not None, f"Failed to resolve decorated overload of {stub.fullname!r}"
           ^^^^^^^^^^^^^^^^
AssertionError: Failed to resolve decorated overload of 'hypothesis.extra.numpy.arrays'

To Reproduce

  • clone https://github.com/numpy/numpy
  • uv venv .venv
  • source .venv/bin/activate
  • uv pip install -r requirements/build_requirements.txt -r requirements/test_requirements.txt
  • spin build
  • create mypy.ini:
    [mypy]
    ignore_errors = True
    
  • create allowlist.txt:
    numpy\._typing.*
    numpy\.typing\.mypy_plugin
    numpy\.conftest.*
    numpy\.random\._generator\.__test__
    numpy(\.\w+)?\.tests.*
    numpy\._core\.cversions
    numpy\.f2py\.__main__
    numpy\.distutils.*
    numpy\.f2py\._backends\._distutils
    numpy\._build_utils.*
    numpy\._pyinstaller.*
    
  • stubtest --mypy-config-file=mypy.ini --allowlist=allowlist.txt --concise --tb numpy

Your Environment

  • Mypy version used: 1.18.2 (compiled: yes)
  • Mypy command-line flags: see above
  • Mypy configuration options from mypy.ini (and other config files): see above
  • Python version used: 3.14.0
  • Operating system and version: Ubuntu 22.04

BTW, adding hypothesis.* to the allowlist doesn't seem to help.

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 Signature.from_overloadedfuncdef und verify_overloadedfuncdef und verfolge anhand des traceback, wie dekorierte @overload-Funktionen aufgelöst werden. Reproduziere das Problem mit dem bereitgestellten NumPy-Setup und dem stubtest-Befehl; als erledigt gilt es, wenn dieser dekorierte overload die Assertion-Fehlermeldung nicht mehr auslöst.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
testing-qa, tooling
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
52/100

Neue Issues direkt in Ihr Postfach

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