-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
I have written (well, copied, from here) a class classproperty
to handle implementing class properties. It works perfectly fine, however when I try and type it as follows (which I think is valid), mypy
raises the below error
class classproperty[T, C]:
def __init__(self, func: Callable[[type[C]], T]):
self.func = func
def __get__(self, _obj: C, owner: type[C]) -> T:
return self.func(owner)
class Test:
@classproperty
def my_property(cls):
return 1
error: Argument 1 to "classproperty" has incompatible type "Callable[[Test], Any]"; expected "Callable[[type[Never]], Any]" [arg-type]
I don't think this is correct, based on my understanding of descriptors and __get__
. I asked a question on stackoverflow about this and it was suggested that this is caused by incorrect assumptions about how __get__
is called
To Reproduce
Gist link here
Expected Behavior
Mypy should pass
Actual Behavior
error: Argument 1 to "classproperty" has incompatible type "Callable[[Test], Any]"; expected "Callable[[type[Never]], Any]" [arg-type]
Your Environment
- Python 3.13.1
mypy==1.15.0
No further config
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong