FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[mypyc] Support @deprecated on functions and methods by rheard · Pull Request #22163 · python/mypy · GitHub

Repository navigation

[mypyc] Support @deprecated on functions and methods - #22163

Open
rheard wants to merge 1 commit into
python:masterfrom
rheard:fix-mypyc-1243
Open

rheard wants to merge 1 commit into
python:masterfrom
rheard:fix-mypyc-1243

Conversation

rheard commented Oct 10, 2026 •
edited
Loading

Copy link
Copy Markdown
Contributor

Fixes mypyc/mypyc#1243.

The runtime @deprecated decorator (PEP 702, from warnings or typing_extensions) stores the message in the __deprecated__ attribute of the function that it wraps. Compiled functions don't support setting attributes, so a module that uses the decorator on a function or a method fails at import:

AttributeError: 'builtin_function_or_method' object has no attribute '__deprecated__'

With this PR mypyc no longer calls the decorator. The compiled function issues the warning itself when it's called. A method isn't a decorated method for mypyc any more, so it's still called natively, and these work as for any other method: property getters and setters, class and static methods, and overriding a native method (or being overridden by one). The implementation of an overloaded function works too. A generator or a coroutine warns when it's created, like with the runtime decorator.

Differences from interpreted Python:

  • The function has no __deprecated__ attribute. This now also applies to nested and async functions,
    where the runtime decorator happened to work. I did this to keep the behavior uniform, but I can leave
    those on the runtime path if that's preferred. It would seem adding support for attributes on compiled methods like __deprecated__ might be a bigger change than even this large PR.

JukkaL commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

This PR has a merge conflict.

rheard commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@JukkaL Seems some of my PRs are arguing over imports. Its been resolved

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@deprecated (PEP 702) on a compiled function or method makes the module fail at import

2 participants


Back | FazBrowse Home | New Git URL