diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py index facedd707..c93cdec48 100644 --- a/fastapi/dependencies/utils.py +++ b/fastapi/dependencies/utils.py @@ -248,6 +248,8 @@ def get_typed_annotation(annotation: Any, globalns: Dict[str, Any]) -> Any: if isinstance(annotation, str): annotation = ForwardRef(annotation) annotation = evaluate_forwardref(annotation, globalns, globalns) + if annotation is type(None): + return None return annotation @@ -255,7 +257,7 @@ def get_typed_return_annotation(call: Callable[..., Any]) -> Any: signature = inspect.signature(call) annotation = signature.return_annotation - if annotation == "None" or annotation is inspect.Signature.empty: + if annotation is inspect.Signature.empty: return None globalns = getattr(call, "__globals__", {})