Content-Length: 220306 | pFad | http://github.com/python/mypy/issues/19178

9F Better support for property-subclasses / read-only descriptors · Issue #19178 · python/mypy · GitHub
Skip to content

Better support for property-subclasses / read-only descriptors #19178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
randolf-scholz opened this issue May 30, 2025 · 0 comments
Open

Better support for property-subclasses / read-only descriptors #19178

randolf-scholz opened this issue May 30, 2025 · 0 comments
Labels

Comments

@randolf-scholz
Copy link
Contributor

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  # ❌
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/mypy/issues/19178

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy