`NoReturn` on `__new__` and `__init__` disables accessing `@classmethod`s and `ClassVar`s directly from the class
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug Report
Annotating __new__(...) -> typing.NoReturn or __init__(...) -> typing.NoReturn causes false positives when accessing @classmethods and typing.ClassVar-annotated attributes.
To Reproduce
from typing import NoReturn, Any, ClassVar
class A:
attr: ClassVar[str] = ""
def __init__(cls, *args: Any, **kwargs: Any) -> NoReturn:
raise RuntimeError
@classmethod
def f(cls) -> None:
pass
class B:
attr: ClassVar[str] = ""
@classmethod
def f(cls) -> None:
pass
Expected Behavior
No issues on any of the following:
A.f()
A.attr
B.f()
B.attr
Actual Behavior
A.f() # mypy: "Callable[[VarArg(Any), KwArg(Any)], NoReturn]" has no attribute "f" [attr-defined]
A.attr # mypy: "Callable[[VarArg(Any), KwArg(Any)], NoReturn]" has no attribute "attr" [attr-defined]
B.f()
B.attr
Your Environment
- Mypy version used: 0.990 and master branch of https://mypy-play.net/
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.10
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con il riproduttore Python fornito e traccia il modo in cui mypy rappresenta le classi il cui new o init restituisce NoReturn. Aggiungi una copertura di regressione per l’accesso a classmethod e ClassVar, assicurandoti che A.f(), A.attr, B.f() e B.attr non producano problemi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100