python / python/mypy

`@deprecated` doesn't work with non-overloaded constructors

Open
#20,103 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-pep-702
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report, To Reproduce, & Actual Behaviour

This is similar to #19588, but that was fixed on master for the case when __init__ is overloaded.

In the non-overloaded case, @deprecated still doesn't report anything (mypy Playground):

To Reproduce

from typing import overload
from typing_extensions import deprecated, Self

class Some:
    @deprecated("reason")
    def __new__(cls, x: str) -> Self: ...

Some('test')  # No reports here

class Some2:
    @deprecated("reason")
    def __init__(self, x: str) -> None: ...

Some2('test')  # No reports here

Expected Behavior

Some('test')  # E: function Some.__new__ is deprecated: reason  [deprecated]
Some2('test')  # E: function Some.__init__ is deprecated: reason  [deprecated]

Your Environment

  • Mypy version used: 1.18.2, master

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 by reproducing the non-overloaded Some.new and Some2.init cases in the linked mypy Playground, then compare their handling with the overloaded case from #19588. Done means both constructor calls emit the expected [deprecated] diagnostics shown in the issue.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.