Skip to content

Support @deprecated on overloaded property setters #21593

@Viicos

Description

@Viicos

Code sample in Mypy playground

from typing import overload
from warnings import deprecated

class A:
    @property
    def t1(self) -> int:
        ...

    @t1.setter
    @deprecated("Setting t is deprecated")
    def t1(self, value: int) -> None:
        ...

    @property
    def t2(self) -> int:
        ...

    @t2.setter
    @overload
    @deprecated("Setting t to None is deprecated")
    def t2(self, value: None) -> None:
        ...

    @t2.setter
    @overload
    def t2(self, value: int) -> None:
        ...

    @t2.setter
    def t2(self, value: int | None) -> None:
        ...

a = A()

a.t1 = 1  # reported
a.t2 = None  # not reported

See also: https://discuss.python.org/t/107604

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions