Skip to content

Conversation

@cbornet
Copy link
Collaborator

@cbornet cbornet commented Jun 20, 2025

dict() is a problematic method name as it clashes with the builtin dict 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 by builtins.dict until the dict() method is removed.

@vercel
Copy link

vercel bot commented Jun 20, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
langchain Ready Ready Preview Comment Sep 9, 2025 9:51am

@dosubot dosubot bot added the size:L label Jun 20, 2025
@cbornet cbornet requested a review from eyurtsev June 20, 2025 16:09
@dosubot dosubot bot added the 🤖:nit label Jun 20, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Jun 20, 2025

Merging this PR will improve performance by 31.76%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚡ 4 improved benchmarks
✅ 9 untouched benchmarks
⏩ 21 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_import_time[tool] 530.2 ms 479.5 ms +10.58%
WallTime test_async_callbacks_in_sync 23.8 ms 18 ms +31.76%
WallTime test_import_time[Document] 189.2 ms 172 ms +10.01%
WallTime test_import_time[ChatPromptTemplate] 639.3 ms 570.4 ms +12.08%

Comparing cbornet:typing-dict (330e108) with master (2ef2388)

Open in CodSpeed

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@codspeed-hq
Copy link

codspeed-hq bot commented Jun 20, 2025

CodSpeed Instrumentation Performance Report

Merging #31685 will not alter performance

Comparing cbornet:typing-dict (92e60c5) with wip-v1.0 (188c015)

Summary

✅ 14 untouched benchmarks

@eyurtsev
Copy link
Collaborator

eyurtsev commented Jun 20, 2025

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 eyurtsev self-assigned this Jun 20, 2025
@cbornet cbornet changed the title core: deprecate problematic dict() method feat(core): deprecate problematic dict() method Jul 13, 2025
@cbornet
Copy link
Collaborator Author

cbornet commented Jul 22, 2025

@eyurtsev candidate for 1.0 ?

@mdrxy mdrxy added this to the v1 milestone Jul 22, 2025
@mdrxy mdrxy removed the 0.4 release label Jul 22, 2025
@mdrxy mdrxy added the core `langchain-core` package issues & PRs label Aug 7, 2025
@mdrxy mdrxy changed the base branch from master to wip-v0.4 August 7, 2025 18:28
@mdrxy mdrxy changed the title feat(core): deprecate problematic dict() method feat(core): deprecate problematic dict() method Aug 7, 2025
@mdrxy mdrxy requested a review from Copilot August 7, 2025 18:39
Copy link
Contributor

Copilot AI left a 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 for dict() across base classes
  • Adds deprecation decorators to existing dict() methods with migration guidance
  • Updates type annotations from dict to typing.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

@mdrxy
Copy link
Member

mdrxy commented Aug 7, 2025

@cbornet please review

@cbornet
Copy link
Collaborator Author

cbornet commented Aug 12, 2025

@cbornet please review

done.

@mdrxy mdrxy changed the base branch from wip-v0.4 to wip-v1.0 August 25, 2025 18:25
@cbornet
Copy link
Collaborator Author

cbornet commented Aug 30, 2025

Something wrong happened with the change of git branch 😢

@github-actions github-actions bot added security core `langchain-core` package issues & PRs langchain `langchain` package issues & PRs infra PRs made that include chores, devops, repo meta changes dependencies Pull requests that update a dependency file (e.g. `pyproject.toml` or `uv.lock`) github_actions Pull requests that update GitHub Actions code cli `langchain-cli` package issues & PRs feature For PRs that implement a new feature; NOT A FEATURE REQUEST and removed feature For PRs that implement a new feature; NOT A FEATURE REQUEST documentation Improvements or additions to documentation infra PRs made that include chores, devops, repo meta changes labels Oct 29, 2025
@cbornet
Copy link
Collaborator Author

cbornet commented Oct 29, 2025

Rebased on master now that v1 was released.

@cbornet cbornet force-pushed the typing-dict branch 2 times, most recently from 8a860e9 to 5071da1 Compare November 24, 2025 17:19
@mdrxy mdrxy removed the security label Dec 11, 2025
@sydney-runkle
Copy link
Collaborator

Hey @cbornet, if you update against master, can help get this across the line

Thanks!

@cbornet
Copy link
Collaborator Author

cbornet commented Dec 13, 2025

Hey @cbornet, if you update against master, can help get this across the line

Rebased against latest master.

@cbornet
Copy link
Collaborator Author

cbornet commented Dec 20, 2025

@sydney-runkle I rebased again and updated the deprecation version. Can you take a look ?

@cbornet cbornet force-pushed the typing-dict branch 2 times, most recently from f91270a to 048b940 Compare December 29, 2025 09:37
@mdrxy mdrxy removed dependencies Pull requests that update a dependency file (e.g. `pyproject.toml` or `uv.lock`) github_actions Pull requests that update GitHub Actions code cli `langchain-cli` package issues & PRs langchain `langchain` package issues & PRs labels Jan 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core `langchain-core` package issues & PRs feature For PRs that implement a new feature; NOT A FEATURE REQUEST

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants