|
|
@ -245,19 +245,23 @@ def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature: |
|
|
|
|
|
|
|
|
class _LenientTypeResolutionDict(dict[str, Any]): |
|
|
class _LenientTypeResolutionDict(dict[str, Any]): |
|
|
def __missing__(self, key: str) -> Any: |
|
|
def __missing__(self, key: str) -> Any: |
|
|
value = vars(builtins).get(key, ForwardRef(key)) |
|
|
return vars(builtins).get(key, ForwardRef(key)) |
|
|
self[key] = value |
|
|
|
|
|
return value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_typed_annotation(annotation: Any, globalns: dict[str, Any]) -> Any: |
|
|
def get_typed_annotation(annotation: Any, globalns: dict[str, Any]) -> Any: |
|
|
if isinstance(annotation, str): |
|
|
if isinstance(annotation, str): |
|
|
annotation = ForwardRef(annotation) |
|
|
annotation = ForwardRef(annotation) |
|
|
if isinstance(annotation, ForwardRef): |
|
|
if isinstance(annotation, ForwardRef): |
|
|
lenient_globalns = _LenientTypeResolutionDict(globalns) |
|
|
|
|
|
annotation = evaluate_forwardref( # ty: ignore[deprecated] |
|
|
annotation = evaluate_forwardref( # ty: ignore[deprecated] |
|
|
annotation, lenient_globalns, lenient_globalns |
|
|
annotation, globalns, globalns |
|
|
) |
|
|
) |
|
|
|
|
|
if isinstance(annotation, ForwardRef): |
|
|
|
|
|
try: |
|
|
|
|
|
annotation = eval( # noqa: S307 |
|
|
|
|
|
annotation.__forward_arg__, _LenientTypeResolutionDict(globalns) |
|
|
|
|
|
) |
|
|
|
|
|
except Exception: |
|
|
|
|
|
pass |
|
|
if annotation is type(None): |
|
|
if annotation is type(None): |
|
|
return None |
|
|
return None |
|
|
return annotation |
|
|
return annotation |
|
|
|