|
5 | 5 | import pathlib |
6 | 6 | from typing import Any, Mapping, TypeVar, cast |
7 | 7 | from datetime import date, datetime |
8 | | -from typing_extensions import Literal, get_args, override, get_type_hints |
| 8 | +from typing_extensions import Literal, get_args, override, get_type_hints as _get_type_hints |
9 | 9 |
|
10 | 10 | import anyio |
11 | 11 | import pydantic |
12 | 12 |
|
13 | 13 | from ._utils import ( |
14 | 14 | is_list, |
15 | 15 | is_given, |
| 16 | + lru_cache, |
16 | 17 | is_mapping, |
17 | 18 | is_iterable, |
18 | 19 | ) |
@@ -109,6 +110,7 @@ class Params(TypedDict, total=False): |
109 | 110 | return cast(_T, transformed) |
110 | 111 |
|
111 | 112 |
|
| 113 | +@lru_cache(maxsize=8096) |
112 | 114 | def _get_annotated_type(type_: type) -> type | None: |
113 | 115 | """If the given type is an `Annotated` type then it is returned, if not `None` is returned. |
114 | 116 |
|
@@ -433,3 +435,13 @@ async def _async_transform_typeddict( |
433 | 435 | else: |
434 | 436 | result[_maybe_transform_key(key, type_)] = await _async_transform_recursive(value, annotation=type_) |
435 | 437 | return result |
| 438 | + |
| 439 | + |
| 440 | +@lru_cache(maxsize=8096) |
| 441 | +def get_type_hints( |
| 442 | + obj: Any, |
| 443 | + globalns: dict[str, Any] | None = None, |
| 444 | + localns: Mapping[str, Any] | None = None, |
| 445 | + include_extras: bool = False, |
| 446 | +) -> dict[str, Any]: |
| 447 | + return _get_type_hints(obj, globalns=globalns, localns=localns, include_extras=include_extras) |
0 commit comments