Skip to content

Conversation

cbornet
Copy link
Collaborator

@cbornet 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.

@cbornet cbornet requested a review from eyurtsev as a code owner October 13, 2025 16:14
@github-actions github-actions bot added core Related to the package `langchain-core` fix labels Oct 13, 2025
Copy link

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
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
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
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
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
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 and removed fix labels Oct 13, 2025
@cbornet 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 and removed fix labels Oct 13, 2025
Copy link
Collaborator

@eyurtsev 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
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
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
Collaborator Author

@cbornet 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
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
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
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
Collaborator Author

Choose a reason for hiding this comment

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

done

@eyurtsev eyurtsev self-assigned this Oct 13, 2025
@cbornet 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 Chores, devops, repo meta changes fix and removed fix infra Chores, devops, repo meta changes labels Oct 14, 2025
@github-actions github-actions bot added the infra Chores, devops, repo meta changes label Oct 14, 2025
@cbornet
Copy link
Collaborator Author

cbornet commented Oct 14, 2025

@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 merged commit 2d5efd7 into langchain-ai:master Oct 17, 2025
72 checks passed
@cbornet 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 Related to the package `langchain-core` fix infra Chores, devops, repo meta changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants