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

Overloaded deprecated method use is not reported #18474

Open
sobolevn opened this issue Jan 15, 2025 · 4 comments · May be fixed by #18477
Open

Overloaded deprecated method use is not reported #18474

sobolevn opened this issue Jan 15, 2025 · 4 comments · May be fixed by #18477
Labels
bug mypy got something wrong topic-overloads topic-pep-702 PEP 702, @deprecated

Comments

@sobolevn
Copy link
Member

Playground: https://mypy-play.net/?mypy=latest&python=3.12&gist=6ae94d19a2160b47cd3c3f2f0bc96553

This code does not produce a [deprecated] error:

# mypy: enable-error-code = deprecated
from typing import overload
from typing_extensions import deprecated

class Some:
    @overload
    @deprecated("reason2")
    def some(self) -> None: ...
    @overload
    def some(self, x: int) -> None: ...

Some().some()  # no error here!

However, this one does:

@overload
@deprecated("reason1")
def func() -> None: ...
@overload
def func(x: int) -> None: ...

func()  # E: overload def () of function __main__.func is deprecated: reason1

Version:

» mypy --version
mypy 1.15.0+dev.c9ed867352b0be6b2cca9df3c856f9047409751b (compiled: no)
@sobolevn sobolevn added bug mypy got something wrong topic-overloads topic-pep-702 PEP 702, @deprecated labels Jan 15, 2025
@sobolevn
Copy link
Member Author

cc @tyralla who solved similar problems.

@tyralla
Copy link
Collaborator

tyralla commented Jan 15, 2025

Strange. I will have a look at it. Thanks for reporting!

@Viicos
Copy link
Contributor

Viicos commented Jan 15, 2025

Is it fixed by #18333, by any chance?

@sobolevn
Copy link
Member Author

sobolevn commented Jan 15, 2025

Nope :(

Using the same gist:

(.venv) ~/Desktop/mypy  master ✗                                                          
» gh pr checkout 18333  

» mypy ex.py
ex.py:5: error: An overloaded function outside a stub file must have an implementation  [no-overload-impl]
ex.py:11: error: overload def () of function ex.func is deprecated: reason1  [deprecated]
ex.py:14: error: An overloaded function outside a stub file must have an implementation  [no-overload-impl]

tyralla added a commit to tyralla/mypy that referenced this issue Jan 15, 2025
Fixes python#18474

It seems I covered overloaded functions, descriptors, and special methods so far but completely forgot about "normal" methods (thanks to @sobolevn for pointing this out).  This addition should do the trick.
@tyralla tyralla linked a pull request Jan 15, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-overloads topic-pep-702 PEP 702, @deprecated
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants