You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NoReturn on __new__ and __init__ disables accessing @classmethods and ClassVars directly from the class #14044
Just hit this bug. It's not just @classmethod or ClassVar: it'll complain about class decorators, ordinary methods, and staticmethod's. Using reveal_type, it appears that mypy thinks that A is a function (a Callable[..., NoReturn]),
and has lost all information about A being a class.
Using reveal_type, it appears that mypy thinks that A is a function (a Callable[..., NoReturn]), and has lost all information about A being a class.
Actually, this is apparently not related to this bug:
classB:
passreveal_type(B) # Revealed type is "def () -> __main__.B"
Anyway, I can confirm that this bug still exists on mypy 1.6.1 and currently on mypy master branch, and occurs both on Python 3.11 and Python 3.12. I can also confirm that pyright doesn't have this bug (i.e. it allows __init__(self) -> NoReturn and then accessing classmethods).
Also hit this. I confirm this bug still persists in 1.7.1 and the master branch, on python versions 3.8 through 3.12.
Is anyone looking into this issue? I find it useful sometimes to define a class that does not instantiate while keeping ClassVars and classmethods available.
Activity
dmcooke commentedon Nov 23, 2022
Just hit this bug. It's not just
@classmethodorClassVar: it'll complain about class decorators, ordinary methods, and staticmethod's. Usingreveal_type, it appears that mypy thinks thatAis a function (aCallable[..., NoReturn]),and has lost all information about
Abeing a class.fofoni commentedon Nov 1, 2023
Just hit this too.
Actually, this is apparently not related to this bug:
Anyway, I can confirm that this bug still exists on mypy 1.6.1 and currently on mypy master branch, and occurs both on Python 3.11 and Python 3.12. I can also confirm that pyright doesn't have this bug (i.e. it allows
__init__(self) -> NoReturnand then accessing classmethods).lkct commentedon Dec 22, 2023
Also hit this. I confirm this bug still persists in 1.7.1 and the master branch, on python versions 3.8 through 3.12.
Is anyone looking into this issue? I find it useful sometimes to define a class that does not instantiate while keeping ClassVars and classmethods available.
henzef commentedon Mar 19, 2024
This is most likely caused by #11216 / #10342 / #13480. Maybe @BvB93 has an idea how to fix it?
BvB93 commentedon Mar 20, 2024
I'm afraid not. My familiarity with mypy's internals is limited, even more so here as this concerns 2.5 year old PRs.