-
Notifications
You must be signed in to change notification settings - Fork 20.2k
feat(core): add PEP 702 __deprecated__ attribute support to @deprecated
#34257
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
Conversation
CodSpeed Performance ReportMerging #34257 will not alter performanceComparing
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds PEP 702 __deprecated__ attribute support to the @deprecated decorator, enabling IDEs and type checkers (like Pyright and VS Code Pylance) to display deprecation warnings inline without requiring code execution. This improves the developer experience by showing strikethrough text and hover messages for deprecated APIs.
Key Changes:
- Added
_build_deprecation_message()helper function to generate PEP 702-compliant deprecation messages - Set
__deprecated__attribute on deprecated classes, properties, and functions/methods - Messages include alternative APIs when specified via
alternativeoralternative_importparameters
| # Set __deprecated__ for PEP 702 (IDE/type checker support) | ||
| prop.__deprecated__ = _build_deprecation_message( # type: ignore[attr-defined] | ||
| alternative=_alternative, | ||
| alternative_import=_alternative_import, | ||
| ) |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as lines 247-251: _alternative and _alternative_import have been modified to include markdown backticks before being passed to _build_deprecation_message. Use the original alternative and alternative_import parameters instead.
Adds PEP 702
__deprecated__attribute support to the@deprecateddecorator, enabling IDE and type checker integration for deprecation warnings.PEP 702 introduced the
__deprecated__attribute convention, which type checkers (Pyright, mypy) and IDEs (VS Code with Pylance, PyCharm) can use to surface deprecations directly in the editor. This PR sets__deprecated__on all objects decorated with@deprecated.With this change, developers using supported IDEs will see:
pyright,mypy)References
typing.deprecatedspecification