python / python/mypy

Support `@deprecated` on overloaded property setters

Open
#21,593 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature topic-overloads
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Mypy playground reproduction in the issue and compare how the deprecated single setter and overloaded setter are handled. Trace the type-checking entry point for property assignments; done means assigning None to t2 reports the deprecated warning without changing the existing t1 behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.