From 6341bc38a202c3220bc6d3d7df67da33c6a02114 Mon Sep 17 00:00:00 2001 From: Lucas Wiman Date: Fri, 24 Jun 2022 10:31:41 -0700 Subject: [PATCH] Traverse __wrapped__ attribute to get to original namespace. --- fastapi/dependencies/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py index f397e333c..08ea969a4 100644 --- a/fastapi/dependencies/utils.py +++ b/fastapi/dependencies/utils.py @@ -245,7 +245,13 @@ def is_scalar_sequence_field(field: ModelField) -> bool: def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature: signature = inspect.signature(call) - globalns = getattr(call, "__globals__", {}) + nsobj = call + while hasattr(nsobj, "__wrapped__"): + # The __wrapped__ attribute is set by decorators, e.g. functools.wraps. + # This while loop allows rereferencing forward references on decorated + # methods. + nsobj = nsobj.__wrapped__ + globalns = getattr(nsobj, "__globals__", {}) typed_params = [ inspect.Parameter( name=param.name,