Open
Description
It seems mypy
applies a bunch of special casing to @property
that does not carry over when using a subclass of property
or when defining a read-only descriptor.
https://mypy-play.net/?mypy=latest&python=3.12&gist=9a1c98026783a48c82f6a92e00acc941
from typing import Callable, ClassVar, Self, overload
class FooAbstract:
@property
def support(self) -> None: ...
class Foo(FooAbstract):
support: ClassVar[None] = None # ✅
# custom Property
class custom_property(property): ...
class BarAbstract:
@custom_property
def support(self) -> None: ...
class Bar(BarAbstract):
support: ClassVar[None] = None # ❌
# custom descriptor
class custom_getter[T, R]:
def __init__(self, fn: Callable[[T], R]) -> None:
self.fn = fn
@overload # type: ignore[no-overload-impl]
def __get__(self, instance: None, owner: type, /) -> Self: ...
@overload
def __get__(self, instance: T, owner: type | None = ..., /) -> R: ...
class BazAbstract:
@custom_getter
def support(self) -> None: ...
class Baz(BazAbstract):
support: ClassVar[None] = None # ❌