"An implementation for an overloaded function is not allowed in a stub file" for overloaded type hint
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
I'm documenting a compiled extension module written in Rust. I write docstrings in my .pyi file so that IDEs and API documentation can automatically pick up those docstrings.
Docstrings are allowed in functions but this errors when a function is overloaded.
To Reproduce
# tmp.pyi
from typing import overload
def fn1() -> None:
"""Call this function."""
@overload
def fn2(a: str) -> str: ...
@overload
def fn2(a: int) -> int: ...
def fn2(a: int | str) -> int | str:
"""Call this function."""
uv run mypy tmp.pyi
gives:
tmp.pyi:10: error: An implementation for an overloaded function is not allowed in a stub file [misc]
Note that this does not error on line 3 for the non-overloaded function.
Expected Behavior
Expected mypy to not error when a docstring is included on a function that has overloads.
Actual Behavior
tmp.pyi:10: error: An implementation for an overloaded function is not allowed in a stub file [misc]
Found 1 error in 1 file (checked 1 source file)
Your Environment
-
Mypy version used:
> uv run mypy --version mypy 1.15.0 (compiled: yes) -
Mypy command-line flags: None, just
uv run mypy tmp.pyi -
Mypy configuration options from
mypy.ini(and other config files): None -
Python version used:
> uv run python --version Python 3.9.21
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, uv run mypy tmp.pyi mit dem Reproducer auszuführen, und verfolge die in Zeile 10 für die überladene Stub-Funktion gemeldete Diagnose. Füge eine Regressionstestabdeckung hinzu, die ihren Docstring zulässt, und bestätige, dass der Befehl ohne diesen Fehler abgeschlossen wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100