mirror of https://github.com/tiangolo/fastapi.git
🐛 Fix support for unevaluated stringified annotations
This commit is contained in:
parent
b0ba272886
commit
6e53ad71ed
|
|
@ -211,7 +211,12 @@ def get_flat_params(dependant: Dependant) -> List[ModelField]:
|
||||||
|
|
||||||
def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature:
|
def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature:
|
||||||
if sys.version_info >= (3, 10):
|
if sys.version_info >= (3, 10):
|
||||||
|
try:
|
||||||
signature = inspect.signature(call, eval_str=True)
|
signature = inspect.signature(call, eval_str=True)
|
||||||
|
except NameError:
|
||||||
|
# Handle type annotations with if TYPE_CHECKING, not used by FastAPI
|
||||||
|
# e.g. dependency return types
|
||||||
|
signature = inspect.signature(call)
|
||||||
else:
|
else:
|
||||||
signature = inspect.signature(call)
|
signature = inspect.signature(call)
|
||||||
unwrapped = inspect.unwrap(call)
|
unwrapped = inspect.unwrap(call)
|
||||||
|
|
@ -240,7 +245,12 @@ def get_typed_annotation(annotation: Any, globalns: Dict[str, Any]) -> Any:
|
||||||
|
|
||||||
def get_typed_return_annotation(call: Callable[..., Any]) -> Any:
|
def get_typed_return_annotation(call: Callable[..., Any]) -> Any:
|
||||||
if sys.version_info >= (3, 10):
|
if sys.version_info >= (3, 10):
|
||||||
|
try:
|
||||||
signature = inspect.signature(call, eval_str=True)
|
signature = inspect.signature(call, eval_str=True)
|
||||||
|
except NameError:
|
||||||
|
# Handle type annotations with if TYPE_CHECKING, not used by FastAPI
|
||||||
|
# e.g. dependency return types
|
||||||
|
signature = inspect.signature(call)
|
||||||
else:
|
else:
|
||||||
signature = inspect.signature(call)
|
signature = inspect.signature(call)
|
||||||
unwrapped = inspect.unwrap(call)
|
unwrapped = inspect.unwrap(call)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue