feat: Python 3.14 support — langchain PEP 649 compatibility#1721
Closed
cluster2600 wants to merge 1 commit intoNVIDIA-NeMo:developfrom
Closed
feat: Python 3.14 support — langchain PEP 649 compatibility#1721cluster2600 wants to merge 1 commit intoNVIDIA-NeMo:developfrom
cluster2600 wants to merge 1 commit intoNVIDIA-NeMo:developfrom
Conversation
Add a _langchain_compat module that handles the dict() method shadowing issue introduced by PEP 649 (deferred annotation evaluation) in Python 3.14. langchain 0.3.x defines Chain.dict() which shadows the builtin dict type during annotation resolution, causing TypeError on Python 3.14. The fix exists in langchain 1.x but has not been backported to 0.3.x. This commit: - Creates _langchain_compat.py with safe import wrappers - Updates langchain_initializer.py to use the compat layer - Updates providers.py to use the compat layer - Updates middleware.py with try/except fallback - Widens python requirement to <3.15 in pyproject.toml Closes NVIDIA-NeMo#1720 Signed-off-by: Maxime Grenu <maxime.grenu@gmail.com>
Author
|
Closing in favour of #1718, which correctly scopes the changes to Python 3.13 support. Python 3.14 is blocked upstream by langchain 0.3.x (PEP 649 / pydantic type evaluation failurs). |
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add comprehensive Python 3.14 support to NeMo Guardrails, addressing PEP 649 (deferred annotation evaluation), asyncio lifecycle changes, native dependency compatibility, and experimental free-threaded (no-GIL) support.
Key changes
_langchain_compat.py) — patchesbuiltins.dictandbuiltins.listinto affected langchain/langchain_core modules before pydantic triggers annotation evaluation_otel_compat.py) — catchesTypeErroralongsideImportErroron OTel imports so tracing degrades gracefullyget_event_loop()withget_or_create_event_loop()/get_running_loop()across 4 modulesannoyoryara-pythonlack 3.14 wheels (77% of initial cascading failures)_test-py314.ymlworkflow,Dockerfile.py314multi-stage build (test + bench targets)docs/python-3.14-migration.mdcovering all changes, Docker usage, and troubleshootingTest results (Python 3.14.3)
Remaining skipped tests:
httpcoreweak-ref bug on Python 3.14asyncio.Timeoutstrictness inIsolatedAsyncioTestCaseteardownCommits (15)
53917c3feat: add Python 3.14 compatibility shim for langchain PEP 649003638efix: handle closed event loops on Python 3.14dae295ebench: add threading benchmark for GIL vs free-threaded comparison4ef48cbperf: add benchmark harness and CI regression gatec3bca1cfix(tracing): add PEP 649 safety for OpenTelemetry imports868fd0efix(compat): harden langchain shim with list patching and langchain_corefb21866fix(asyncio): replace deprecated get_event_loop() callsc81848dfix(deps): add skip guards for annoy and yara8ee7159ci: add Python 3.14 CI workflow and multi-stage Dockerfilea7e48f6docs: add migration guide, compat tests, and triage report75b5a4bfix(docker): add pytest-timeout to test stage570856dfix(docker): add fastembed, fix package metadatadd7bd69fix(tests): add importorskip guards for pytest-httpx164203cdocs: add rich dependency note and Pydantic V1 warningb3a3ebefix(tests): skip tests hitting upstream Python 3.14 bugsRelated
Test plan
_langchain_compat.py— 16 tests covering patching, idempotency, edge cases