-
Notifications
You must be signed in to change notification settings - Fork 19.1k
feat(core): deprecate problematic dict()
method
#31685
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: wip-v1.0
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
CodSpeed WallTime Performance ReportMerging #31685 will not alter performanceComparing
|
CodSpeed Instrumentation Performance ReportMerging #31685 will not alter performanceComparing Summary
|
We could merge as part of the 0.4 release. Unclear yet whether this change should be made -- better not to clash with a built in for new code, but for existing code this would be weighed from a cost benefit analysis to end users |
@eyurtsev candidate for 1.0 ? |
dict()
method
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 deprecates the problematic dict()
method that clashes with Python's builtin dict
type annotation and replaces it with an asdict()
method inspired by dataclasses. The change addresses type annotation conflicts by introducing proper deprecation warnings and updating internal usage.
Key changes:
- Introduces
asdict()
method as replacement fordict()
across base classes - Adds deprecation decorators to existing
dict()
methods with migration guidance - Updates type annotations from
dict
totyping.Dict
where the builtin conflicts with the method name
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
File | Description |
---|---|
libs/core/langchain_core/prompts/base.py |
Adds asdict() method, deprecates dict() , updates type annotations and internal usage |
libs/core/langchain_core/output_parsers/base.py |
Adds asdict() method and deprecates dict() with proper decorator |
libs/core/langchain_core/language_models/llms.py |
Updates type annotations, adds asdict() method, and replaces internal dict() calls |
libs/core/langchain_core/language_models/chat_models.py |
Updates type annotations, adds asdict() method, and replaces internal usage |
@cbornet please review |
0018be9
to
82a3f22
Compare
done. |
Something wrong happened with the change of git branch 😢 |
fixed it. |
@model_validator(mode="before") | ||
@classmethod | ||
def raise_deprecation(cls, values: dict) -> Any: | ||
def raise_deprecation(cls, values: typing.Dict) -> Any: # noqa: UP006 |
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.
We're dropping 3.9.
def raise_deprecation(cls, values: typing.Dict) -> Any: # noqa: UP006 | |
def raise_deprecation(cls, values: dict) -> Any: |
will this work?
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.
No it wouldn't.
But I did it another way to avoid the UP006 by using builtins.dict
.
PTAL
raise NotImplementedError(msg) | ||
|
||
def dict(self, **kwargs: Any) -> dict: | ||
@deprecated("0.3.61", alternative="asdict", removal="1.0") |
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.
Will need to update this - deprecate in 1.0, remove in 2.0
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.
done
ffb2847
to
c8f3f47
Compare
dict()
is a problematic method name as it clashes with the builtindict
used as a type annotation.This PR replaces it with an
asdict
method (inspired by dataclasses).It also fixes a few places where
dict
must be replaced bybuiltins.dict
until thedict()
method is removed.