Decorator becomes untyped when it accepts an object of the same type as a certain global.
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
A decorator becomes untyped when it accepts an argument for which we have another instance, globally defined and referred to in the same scope.
The comments in the example should make the bug much more clear.
I had no idea how to describe this issue or search for it, so no idea whether it was reported before.
To Reproduce
from typing import Callable
class Something:
pass
def decorator(buffer: Something) -> Callable[[Callable[[], None]], Callable[[], None]]:
return lambda x: x
def main() -> None:
something # Comment out this line and everything is fine.
another_something = Something()
@decorator(another_something)
def func() -> None:
return
something = Something() # Move this above `main` and everything is fine.
Expected Behavior
The code snippet should pass.
Actual Behavior
$ mypy --strict /tmp/test.py
test.py:16: error: Untyped decorator makes function "func" untyped
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 0.982
- Mypy command-line flags: --strict
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.9.13
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, das Snippet mit mypy --strict nachzustellen und das Verhalten zu vergleichen, wenn das globale something entfernt oder oberhalb von main verschoben wird. Verfolge die Typinferenz des Decorators und den an diesem Beispiel beteiligten Namensauflösungspfad. Als erledigt gilt die Aufgabe, wenn das ursprüngliche Snippet die strikte Prüfung besteht, ohne einen untypisierten Decorator zu melden.
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
- 35/100