wweber 2 days ago
committed by GitHub
parent
commit
888b6f6d03
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 18
      fastapi/dependencies/utils.py

18
fastapi/dependencies/utils.py

@ -228,9 +228,25 @@ def get_flat_params(dependant: Dependant) -> List[ModelField]:
return path_params + query_params + header_params + cookie_params
def get_globalns(call: Callable[..., Any]) -> Dict[str, Any]:
source_func: Any
if hasattr(call, "__globals__"):
# If the callable has __globals__ set, use that
source_func = call
elif isinstance(call, type):
# If the callable is a class, its dependencies are declared on __init__
source_func = call.__init__
else:
# For callable instances of classes, the dependencies are declared on __call__
source_func = call.__call__
return cast(Dict[str, Any], getattr(source_func, "__globals__", {}))
def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature:
signature = inspect.signature(call)
globalns = getattr(call, "__globals__", {})
globalns = get_globalns(call)
typed_params = [
inspect.Parameter(
name=param.name,

Loading…
Cancel
Save