-
Notifications
You must be signed in to change notification settings - Fork 20.1k
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,6 +28,27 @@ | |||||||||
| from langchain_core._api.internal import is_caller_internal | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def _build_deprecation_message( | ||||||||||
| *, | ||||||||||
| alternative: str = "", | ||||||||||
| alternative_import: str = "", | ||||||||||
| ) -> str: | ||||||||||
| """Build a simple deprecation message for __deprecated__ attribute (PEP 702). | ||||||||||
|
|
||||||||||
| Args: | ||||||||||
| alternative: An alternative API name. | ||||||||||
| alternative_import: A fully qualified import path for the alternative. | ||||||||||
|
|
||||||||||
| Returns: | ||||||||||
| A deprecation message string for IDE/type checker display. | ||||||||||
| """ | ||||||||||
| if alternative_import: | ||||||||||
| return f"Use {alternative_import} instead." | ||||||||||
| if alternative: | ||||||||||
| return f"Use {alternative} instead." | ||||||||||
| return "Deprecated." | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class LangChainDeprecationWarning(DeprecationWarning): | ||||||||||
| """A class for issuing deprecation warnings for LangChain users.""" | ||||||||||
|
|
||||||||||
|
|
@@ -223,6 +244,11 @@ def warn_if_direct_instance( | |||||||||
| obj.__init__ = functools.wraps(obj.__init__)( # type: ignore[misc] | ||||||||||
| warn_if_direct_instance | ||||||||||
| ) | ||||||||||
| # Set __deprecated__ for PEP 702 (IDE/type checker support) | ||||||||||
| obj.__deprecated__ = _build_deprecation_message( # type: ignore[attr-defined] | ||||||||||
| alternative=_alternative, | ||||||||||
| alternative_import=_alternative_import, | ||||||||||
|
Comment on lines
+249
to
+250
|
||||||||||
| alternative=_alternative, | |
| alternative_import=_alternative_import, | |
| 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.
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 and 347-351: _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.
| alternative=_alternative, | |
| alternative_import=_alternative_import, | |
| alternative=alternative, | |
| alternative_import=alternative_import, |
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.
The new
__deprecated__attribute functionality lacks test coverage. Tests should verify that:__deprecated__attribute is set correctly on deprecated functions, classes, and propertiesExample test: