Skip to content

fix(core): support for Python 3.14#33461

Merged
Sydney Runkle (sydney-runkle) merged 7 commits into
langchain-ai:masterfrom
cbornet:python-3.14
Oct 17, 2025
Merged

fix(core): support for Python 3.14#33461
Sydney Runkle (sydney-runkle) merged 7 commits into
langchain-ai:masterfrom
cbornet:python-3.14

Conversation

@cbornet
Copy link
Copy Markdown
Collaborator

@cbornet Christophe Bornet (cbornet) commented Oct 13, 2025

  • Fix detection of support of context in asyncio.create_task
  • Fix: in Python 3.14 asyncio.get_event_loop() raises an exception if there's no running loop
  • Bump pydantic to version 2.12
  • Skips tests with pydantic v1 models as they are not supported with Python 3.14
  • Run core tests with Python 3.14 in CI.

@github-actions github-actions Bot added core `langchain-core` package issues & PRs fix For PRs that implement a fix labels Oct 13, 2025
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Oct 13, 2025

CodSpeed Performance Report

Merging #33461 will degrade performances by 12.27%

Comparing cbornet:python-3.14 (f0e5668) with master (1d22735)

⚠️ 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.

Summary

❌ 4 (👁 4) regressions
✅ 9 untouched
⏩ 21 skipped1

Benchmarks breakdown

Mode Benchmark BASE HEAD Change
👁 WallTime test_import_time[ChatPromptTemplate] 572.6 ms 652.6 ms -12.27%
👁 WallTime test_import_time[LangChainTracer] 412.3 ms 461.9 ms -10.73%
👁 WallTime test_import_time[PydanticOutputParser] 505.2 ms 574.5 ms -12.05%
👁 WallTime test_import_time[RunnableLambda] 473 ms 534.9 ms -11.57%

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.

The coroutine with the context.
"""
if asyncio_accepts_context():
if sys.version_info >= (3, 11):
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signature we get in py314 is asyncio.create_task(coro, **kwargs) so we can't check the presence of context.
There's very little chance that support for context in create_task will ever be removed so I think we can just do a version check here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to fix the implementation of the function: asyncio_accepts_context instead of not using it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


loop = asyncio.get_event_loop()
try:
loop = asyncio.get_event_loop()
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asyncio.get_event_loop raises an exception in Python 3.14 if there's no running loop (was a warning in previous versions)

@github-actions github-actions Bot added fix For PRs that implement a fix and removed fix For PRs that implement a fix labels Oct 13, 2025
@cbornet Christophe Bornet (cbornet) force-pushed the python-3.14 branch 3 times, most recently from c05fe27 to 42fcb96 Compare October 13, 2025 17:04
@github-actions github-actions Bot added fix For PRs that implement a fix and removed fix For PRs that implement a fix labels Oct 13, 2025
Copy link
Copy Markdown
Collaborator

@eyurtsev Eugene Yurtsev (eyurtsev) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very reasonable to me left a few nit comments

The coroutine with the context.
"""
if asyncio_accepts_context():
if sys.version_info >= (3, 11):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to fix the implementation of the function: asyncio_accepts_context instead of not using it?

f_or_c: Literal["F", "C"]
forecast: str

_FORECAST_MODELS_TYPES |= type[ForecastV1]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_FORECAST_MODELS_TYPES -- which type is this? something looks off. If it's meant to be a set or a list could we use the dedicated APIs for adding an element instead of relying on the operator shorthand (|=) to maximize for readability?

Copy link
Copy Markdown
Collaborator Author

@cbornet Christophe Bornet (cbornet) Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_FORECAST_MODELS_TYPES is a typing.Union of types. Used for type checking. I don’t think there is an API to do this. But there’s maybe a simpler way to write it. I’ll have a look.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to simplify. PTAL.



@pytest.mark.skipif(
sys.version_info >= (3, 14), reason="Pydantic v1 not supported with Python 3.14+"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could be helpful to paraphrase the reason a bit (wording is confusing w/ respect to whether this is pydantic 1 or pydantic 2's v1 namespace)

You could say The pydantic.v1 namespace is not supported with python 3.14+ or something like that (to make it clear that it's specifically v1 within pydantic 2)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Good idea!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@cbornet Christophe Bornet (cbornet) force-pushed the python-3.14 branch 2 times, most recently from b845d61 to 29c5034 Compare October 14, 2025 15:40
@github-actions github-actions Bot added infra PRs made that include chores, devops, repo meta changes fix For PRs that implement a fix and removed fix For PRs that implement a fix infra PRs made that include chores, devops, repo meta changes labels Oct 14, 2025
@github-actions github-actions Bot added the infra PRs made that include chores, devops, repo meta changes label Oct 14, 2025
@cbornet
Copy link
Copy Markdown
Collaborator Author

Eugene Yurtsev (@eyurtsev) in the end, I added the upgrade to pydantic 2.12 to this PR.
This way it can be validated in CI with Python 3.14.

@sydney-runkle Sydney Runkle (sydney-runkle) merged commit 2d5efd7 into langchain-ai:master Oct 17, 2025
72 checks passed
@cbornet Christophe Bornet (cbornet) deleted the python-3.14 branch October 17, 2025 10:12
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 fix For PRs that implement a fix infra PRs made that include chores, devops, repo meta changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants