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
Using Never as return type for __new__ results in classmethods not being recognised. Inferred type for class is Callable[[], NoReturn]. #16981
If the classmethod __new__ of a class is marked as returning Never, Mypy does not recognise the existence of attributes for the class (whose type it believes to be Callable[[], NoReturn]).
To Reproduce
fromtypingimportNever, SelfclassA:
x: int@classmethoddef_new(cls, x: int) ->Self:
instance=super().__new__(cls)
instance.x=xreturninstancedef__new__(cls) ->Never:
raiseTypeError("Class 'A' should not be instanced directly.")
a=A._new(10) # Mypy Error: attr-defined# "Callable[[], NoReturn]" has no attribute "_new"
fromtypingimportClassVar, NeverclassA:
attr: ClassVar[int] =20def__new__(cls) ->Never:
raiseTypeError("Class 'A' should not be instanced directly.")
a=A.attr# Mypy Error: attr-defined# "Callable[[], NoReturn]" has no attribute "attr"
Activity