Skip to content

Commit 6ea03ab

Browse files
authored
style(core): drop python 39 linting target for 3.10 (#33286)
1 parent 99d8504 commit 6ea03ab

File tree

155 files changed

+2445
-2738
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+2445
-2738
lines changed

libs/core/langchain_core/_api/beta_decorator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import functools
1515
import inspect
1616
import warnings
17-
from collections.abc import Generator
18-
from typing import Any, Callable, TypeVar, Union, cast
17+
from collections.abc import Callable, Generator
18+
from typing import Any, TypeVar, cast
1919

2020
from langchain_core._api.internal import is_caller_internal
2121

@@ -27,7 +27,7 @@ class LangChainBetaWarning(DeprecationWarning):
2727
# PUBLIC API
2828

2929

30-
T = TypeVar("T", bound=Union[Callable[..., Any], type])
30+
T = TypeVar("T", bound=Callable[..., Any] | type)
3131

3232

3333
def beta(

libs/core/langchain_core/_api/deprecation.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
import functools
1515
import inspect
1616
import warnings
17-
from collections.abc import Generator
17+
from collections.abc import Callable, Generator
1818
from typing import (
1919
Any,
20-
Callable,
2120
ParamSpec,
2221
TypeVar,
23-
Union,
2422
cast,
2523
)
2624

@@ -42,7 +40,7 @@ class LangChainPendingDeprecationWarning(PendingDeprecationWarning):
4240

4341

4442
# Last Any should be FieldInfoV1 but this leads to circular imports
45-
T = TypeVar("T", bound=Union[type, Callable[..., Any], Any])
43+
T = TypeVar("T", bound=type | Callable[..., Any] | Any)
4644

4745

4846
def _validate_deprecation_params(
@@ -276,27 +274,25 @@ def finalize(wrapper: Callable[..., Any], new_doc: str) -> T: # noqa: ARG001
276274
if not _obj_type:
277275
_obj_type = "attribute"
278276
wrapped = None
279-
_name = _name or cast("Union[type, Callable]", obj.fget).__qualname__
277+
_name = _name or cast("type | Callable", obj.fget).__qualname__
280278
old_doc = obj.__doc__
281279

282280
class _DeprecatedProperty(property):
283281
"""A deprecated property."""
284282

285283
def __init__(
286284
self,
287-
fget: Union[Callable[[Any], Any], None] = None,
288-
fset: Union[Callable[[Any, Any], None], None] = None,
289-
fdel: Union[Callable[[Any], None], None] = None,
290-
doc: Union[str, None] = None,
285+
fget: Callable[[Any], Any] | None = None,
286+
fset: Callable[[Any, Any], None] | None = None,
287+
fdel: Callable[[Any], None] | None = None,
288+
doc: str | None = None,
291289
) -> None:
292290
super().__init__(fget, fset, fdel, doc)
293291
self.__orig_fget = fget
294292
self.__orig_fset = fset
295293
self.__orig_fdel = fdel
296294

297-
def __get__(
298-
self, instance: Any, owner: Union[type, None] = None
299-
) -> Any:
295+
def __get__(self, instance: Any, owner: type | None = None) -> Any:
300296
if instance is not None or owner is not None:
301297
emit_warning()
302298
if self.fget is None:
@@ -315,7 +311,7 @@ def __delete__(self, instance: Any) -> None:
315311
if self.fdel is not None:
316312
self.fdel(instance)
317313

318-
def __set_name__(self, owner: Union[type, None], set_name: str) -> None:
314+
def __set_name__(self, owner: type | None, set_name: str) -> None:
319315
nonlocal _name
320316
if _name == "<lambda>":
321317
_name = set_name
@@ -330,7 +326,7 @@ def finalize(wrapper: Callable[..., Any], new_doc: str) -> T: # noqa: ARG001
330326
)
331327

332328
else:
333-
_name = _name or cast("Union[type, Callable]", obj).__qualname__
329+
_name = _name or cast("type | Callable", obj).__qualname__
334330
if not _obj_type:
335331
# edge case: when a function is within another function
336332
# within a test, this will call it a "method" not a "function"

libs/core/langchain_core/_api/path.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
from pathlib import Path
3-
from typing import Optional, Union
43

54
HERE = Path(__file__).parent
65

@@ -9,9 +8,7 @@
98
SEPARATOR = os.sep
109

1110

12-
def get_relative_path(
13-
file: Union[Path, str], *, relative_to: Path = PACKAGE_DIR
14-
) -> str:
11+
def get_relative_path(file: Path | str, *, relative_to: Path = PACKAGE_DIR) -> str:
1512
"""Get the path of the file as a relative path to the package directory.
1613
1714
Args:
@@ -27,9 +24,9 @@ def get_relative_path(
2724

2825

2926
def as_import_path(
30-
file: Union[Path, str],
27+
file: Path | str,
3128
*,
32-
suffix: Optional[str] = None,
29+
suffix: str | None = None,
3330
relative_to: Path = PACKAGE_DIR,
3431
) -> str:
3532
"""Path of the file as a LangChain import exclude langchain top namespace.

libs/core/langchain_core/_import_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from importlib import import_module
2-
from typing import Union
32

43

54
def import_attr(
65
attr_name: str,
7-
module_name: Union[str, None],
8-
package: Union[str, None],
6+
module_name: str | None,
7+
package: str | None,
98
) -> object:
109
"""Import an attribute from a module located in a package.
1110

libs/core/langchain_core/agents.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import json
3131
from collections.abc import Sequence
32-
from typing import Any, Literal, Union
32+
from typing import Any, Literal
3333

3434
from langchain_core.load.serializable import Serializable
3535
from langchain_core.messages import (
@@ -49,7 +49,7 @@ class AgentAction(Serializable):
4949

5050
tool: str
5151
"""The name of the Tool to execute."""
52-
tool_input: Union[str, dict]
52+
tool_input: str | dict
5353
"""The input to pass in to the Tool."""
5454
log: str
5555
"""Additional information to log about the action.
@@ -62,9 +62,7 @@ class AgentAction(Serializable):
6262
type: Literal["AgentAction"] = "AgentAction"
6363

6464
# Override init to support instantiation by position for backward compat.
65-
def __init__(
66-
self, tool: str, tool_input: Union[str, dict], log: str, **kwargs: Any
67-
):
65+
def __init__(self, tool: str, tool_input: str | dict, log: str, **kwargs: Any):
6866
"""Create an AgentAction.
6967
7068
Args:

libs/core/langchain_core/caches.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from abc import ABC, abstractmethod
2727
from collections.abc import Sequence
28-
from typing import Any, Optional
28+
from typing import Any
2929

3030
from typing_extensions import override
3131

@@ -52,7 +52,7 @@ class BaseCache(ABC):
5252
"""
5353

5454
@abstractmethod
55-
def lookup(self, prompt: str, llm_string: str) -> Optional[RETURN_VAL_TYPE]:
55+
def lookup(self, prompt: str, llm_string: str) -> RETURN_VAL_TYPE | None:
5656
"""Look up based on prompt and llm_string.
5757
5858
A cache implementation is expected to generate a key from the 2-tuple
@@ -97,7 +97,7 @@ def update(self, prompt: str, llm_string: str, return_val: RETURN_VAL_TYPE) -> N
9797
def clear(self, **kwargs: Any) -> None:
9898
"""Clear cache that can take additional keyword arguments."""
9999

100-
async def alookup(self, prompt: str, llm_string: str) -> Optional[RETURN_VAL_TYPE]:
100+
async def alookup(self, prompt: str, llm_string: str) -> RETURN_VAL_TYPE | None:
101101
"""Async look up based on prompt and llm_string.
102102
103103
A cache implementation is expected to generate a key from the 2-tuple
@@ -149,7 +149,7 @@ async def aclear(self, **kwargs: Any) -> None:
149149
class InMemoryCache(BaseCache):
150150
"""Cache that stores things in memory."""
151151

152-
def __init__(self, *, maxsize: Optional[int] = None) -> None:
152+
def __init__(self, *, maxsize: int | None = None) -> None:
153153
"""Initialize with empty cache.
154154
155155
Args:
@@ -167,7 +167,7 @@ def __init__(self, *, maxsize: Optional[int] = None) -> None:
167167
raise ValueError(msg)
168168
self._maxsize = maxsize
169169

170-
def lookup(self, prompt: str, llm_string: str) -> Optional[RETURN_VAL_TYPE]:
170+
def lookup(self, prompt: str, llm_string: str) -> RETURN_VAL_TYPE | None:
171171
"""Look up based on prompt and llm_string.
172172
173173
Args:
@@ -201,7 +201,7 @@ def clear(self, **kwargs: Any) -> None:
201201
"""Clear cache."""
202202
self._cache = {}
203203

204-
async def alookup(self, prompt: str, llm_string: str) -> Optional[RETURN_VAL_TYPE]:
204+
async def alookup(self, prompt: str, llm_string: str) -> RETURN_VAL_TYPE | None:
205205
"""Async look up based on prompt and llm_string.
206206
207207
Args:

0 commit comments

Comments
 (0)