The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
refactor(langchain-classic): remove code for Python < 3.10 (#38194)
Christophe Bornet9ac8882a2c40
diff --git a/libs/core/langchain_core/runnables/configurable.py b/libs/core/langchain_core/runnables/configurable.pyindex 415c30d4d2..fce98b5726 100644--- a/libs/core/langchain_core/runnables/configurable.py+++ b/libs/core/langchain_core/runnables/configurable.py@@ -620,7 +620,7 @@ class RunnableConfigurableAlternatives(DynamicRunnable[Input, Output]):{**config,"configurable": {- _strremoveprefix(k, f"{self.which.id}=={which}/"): v+ k.removeprefix(f"{self.which.id}=={which}/"): vfor k, v in config.get("configurable", {}).items()},},@@ -637,11 +637,6 @@ class RunnableConfigurableAlternatives(DynamicRunnable[Input, Output]):raise ValueError(msg)-def _strremoveprefix(s: str, prefix: str) -> str:- """`str.removeprefix()` is only available in Python 3.9+."""- return s.replace(prefix, "", 1) if s.startswith(prefix) else s--def prefix_config_spec(spec: ConfigurableFieldSpec, prefix: str) -> ConfigurableFieldSpec:diff --git a/libs/core/langchain_core/utils/aiter.py b/libs/core/langchain_core/utils/aiter.pyindex 912fb32e70..8d74a50fb7 100644--- a/libs/core/langchain_core/utils/aiter.py+++ b/libs/core/langchain_core/utils/aiter.py@@ -214,7 +214,7 @@ class Tee(Generic[T]):lock: The lock to synchronise access to the shared buffers."""- self._iterator = iterable.__aiter__() # before 3.10 aiter() doesn't exist+ self._iterator = aiter(iterable)self._buffers: list[deque[T]] = [deque() for _ in range(n)]self._children = tuple(tee_peer(diff --git a/libs/core/langchain_core/utils/function_calling.py b/libs/core/langchain_core/utils/function_calling.pyindex e2e21ddc28..748162e3e0 100644--- a/libs/core/langchain_core/utils/function_calling.py+++ b/libs/core/langchain_core/utils/function_calling.py@@ -57,10 +57,8 @@ _ORIGIN_MAP: dict[type, Any] = {collections.abc.Mapping: typing.Mapping,collections.abc.Sequence: typing.Sequence,collections.abc.MutableMapping: typing.MutableMapping,+ types.UnionType: Union,}-# Add UnionType mapping for Python 3.10+-if hasattr(types, "UnionType"):- _ORIGIN_MAP[types.UnionType] = Unionclass FunctionDescription(TypedDict):diff --git a/libs/core/tests/unit_tests/output_parsers/test_pydantic_parser.py b/libs/core/tests/unit_tests/output_parsers/test_pydantic_parser.pyindex 0451b26ce4..8532754bd7 100644--- a/libs/core/tests/unit_tests/output_parsers/test_pydantic_parser.py+++ b/libs/core/tests/unit_tests/output_parsers/test_pydantic_parser.py@@ -172,8 +172,6 @@ def test_pydantic_output_parser_type_inference() -> None:foo: intbar: str- # Ignoring mypy error that appears in python 3.8, but not 3.11.- # This seems to be functionally correct, so we'll ignore the error.pydantic_parser = PydanticOutputParser[SampleModel](pydantic_object=SampleModel)schema = pydantic_parser.get_output_jsonschema()diff --git a/libs/langchain/pyproject.toml b/libs/langchain/pyproject.tomlindex f297f6561b..c8cb02898b 100644--- a/libs/langchain/pyproject.toml+++ b/libs/langchain/pyproject.toml@@ -74,7 +74,6 @@ test = ["pytest-xdist<4.0.0,>=3.6.1","numpy>=1.26.4; python_version<'3.13'","numpy>=2.1.0; python_version>='3.13'",- "cffi","freezegun>=1.2.2,<2.0.0","responses>=0.22.0,<1.0.0","lark>=1.1.5,<2.0.0",@@ -94,7 +93,6 @@ test_integration = []lint = ["ruff>=0.15.0,<0.16.0",- "cffi",]typing = ["mypy>=2.1.0,<2.2.0",diff --git a/libs/langchain/tests/unit_tests/test_dependencies.py b/libs/langchain/tests/unit_tests/test_dependencies.pyindex ffa711be69..8f80580568 100644--- a/libs/langchain/tests/unit_tests/test_dependencies.py+++ b/libs/langchain/tests/unit_tests/test_dependencies.py@@ -75,8 +75,6 @@ def test_test_group_dependencies(uv_conf: Mapping[str, Any]) -> None:"syrupy","toml","requests-mock",- # TODO: temporary hack since cffi 1.17.1 doesn't work with py 3.9.- "cffi","numpy",],)diff --git a/libs/langchain/uv.lock b/libs/langchain/uv.lockindex 81a2b486fd..f4a72bf362 100644--- a/libs/langchain/uv.lock+++ b/libs/langchain/uv.lock@@ -2769,11 +2769,9 @@ dev = [{ name = "setuptools" },]lint = [- { name = "cffi" },{ name = "ruff" },]test = [- { name = "cffi" },{ name = "freezegun" },{ name = "langchain-openai" },{ name = "langchain-tests" },@@ -2849,12 +2847,8 @@ dev = [{ name = "playwright", specifier = ">=1.28.0,<2.0.0" },{ name = "setuptools", specifier = ">=67.6.1,<83.0.0" },]-lint = [- { name = "cffi" },- { name = "ruff", specifier = ">=0.15.0,<0.16.0" },-]+lint = [{ name = "ruff", specifier = ">=0.15.0,<0.16.0" }]test = [- { name = "cffi" },{ name = "freezegun", specifier = ">=1.2.2,<2.0.0" },{ name = "langchain-openai", editable = "../partners/openai" },{ name = "langchain-tests", editable = "../standard-tests" },@@ -2954,7 +2948,7 @@ dependencies = [[package.metadata]requires-dist = [{ name = "jsonpatch", specifier = ">=1.33.0,<2.0.0" },- { name = "langchain-protocol", specifier = ">=0.0.14" },+ { name = "langchain-protocol", specifier = ">=0.0.17" },{ name = "langsmith", specifier = ">=0.3.45,<1.0.0" },{ name = "packaging", specifier = ">=23.2.0" },{ name = "pydantic", specifier = ">=2.7.4,<3.0.0" },@@ -3183,14 +3177,14 @@ wheels = [[[package]]name = "langchain-protocol"-version = "0.0.14"+version = "0.0.17"source = { registry = "https://pypi.org/simple" }dependencies = [{ name = "typing-extensions" },]-sdist = { url = "https://files.pythonhosted.org/packages/05/bf/efb5e2ed832e4d6d45590e25a9e5191986b291b543bc6a807b48bee070b0/langchain_protocol-0.0.14.tar.gz", hash = "sha256:bc1e8553122e6ede310280462d5813023a172ff2785ccbbdec54d43f3a15e5f2", size = 5862, upload-time = "2026-04-29T16:40:18.657Z" }+sdist = { url = "https://files.pythonhosted.org/packages/44/b3/4e2429876c7a35585618caa2b9f9089f7162a6b50562b614ad82ac11c17e/langchain_protocol-0.0.17.tar.gz", hash = "sha256:e7cbe58c205df4b4fd87dc6d5bb23f10e13b236d0e2e1b0b9d05bc2b648f3eea", size = 6026, upload-time = "2026-06-12T18:39:51.923Z" }wheels = [- { url = "https://files.pythonhosted.org/packages/c2/e9/06c47ecb2aff08f83dfa30058da3bf86be64862c19569043ed5331bbeecd/langchain_protocol-0.0.14-py3-none-any.whl", hash = "sha256:ffc35089779bd8ca217015180cef5e660fc3b074efdaa0f2e95df73583f1a047", size = 6984, upload-time = "2026-04-29T16:40:17.841Z" },+ { url = "https://files.pythonhosted.org/packages/13/0a/a1bfe72c6ec856e99773bbd96c8086421e554b3693d0142b9ea009c6ac92/langchain_protocol-0.0.17-py3-none-any.whl", hash = "sha256:982a08fe152586ed10d4ff3d538c2e0b5766e5f307cdea325e10be3f2c17cae6", size = 7096, upload-time = "2026-06-12T18:39:50.973Z" },][[package]]