Skip to content

Generic descriptors with a deprecated __get__ overload #18323

Description

@Viicos
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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions