Skip to content
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

Generic descriptors with a deprecated __get__ overload #18323

Open
Viicos opened this issue Dec 21, 2024 · 0 comments · May be fixed by #18333
Open

Generic descriptors with a deprecated __get__ overload #18323

Viicos opened this issue Dec 21, 2024 · 0 comments · May be fixed by #18333
Labels
feature topic-descriptors Properties, class vs. instance attributes topic-pep-702 PEP 702, @deprecated

Comments

@Viicos
Copy link
Contributor

Viicos commented Dec 21, 2024

from typing import Any, Generic, TypeVar, overload

from typing_extensions import deprecated

T = TypeVar("T")


class Works:
    @overload
    def __get__(self, instance: None, objtype: Any) -> int: ...
    @overload
    @deprecated(
        "Accessing this attribute on the instance is deprecated",
        category=None,
    )
    def __get__(self, instance: 'Class', objtype: Any) -> int: ...


class Fails(Generic[T]):
    @overload
    def __get__(self, instance: None, objtype: Any) -> T: ...
    @overload
    @deprecated(
        "Accessing this attribute on the instance is deprecated",
        category=None,
    )
    def __get__(self, instance: 'Class', objtype: Any) -> T: ...


class Class:
    works = Works()
    fails = Fails[int]()


Class().works
Class().fails
$ mypy --enable-error-code=deprecated --disable-error-code=no-overload-impl repro.py
repro.py:86: error: overload def (self: repro.Works, instance: repro.Class, objtype: Any) -> builtins.int of function repro.Works.__get__ is deprecated: Accessing this attribute on the instance is deprecated  [deprecated]

(on mypy 1.14)

@Viicos Viicos added the feature label Dec 21, 2024
@brianschubert brianschubert added topic-pep-702 PEP 702, @deprecated topic-descriptors Properties, class vs. instance attributes labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-descriptors Properties, class vs. instance attributes topic-pep-702 PEP 702, @deprecated
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants