MCPcopy
hub / github.com/fastapi/fastapi / get_dependant

Function get_dependant

fastapi/dependencies/utils.py:286–359  ·  view source on GitHub ↗
(
    *,
    path: str,
    call: Callable[..., Any],
    name: str | None = None,
    own_oauth_scopes: list[str] | None = None,
    parent_oauth_scopes: list[str] | None = None,
    use_cache: bool = True,
    scope: Literal["function", "request"] | None = None,
)

Source from the content-addressed store, hash-verified

284
285
286def get_dependant(
287 *,
288 path: str,
289 call: Callable[..., Any],
290 name: str | None = None,
291 own_oauth_scopes: list[str] | None = None,
292 parent_oauth_scopes: list[str] | None = None,
293 use_cache: bool = True,
294 scope: Literal["function", "request"] | None = None,
295) -> Dependant:
296 dependant = Dependant(
297 call=call,
298 name=name,
299 path=path,
300 use_cache=use_cache,
301 scope=scope,
302 own_oauth_scopes=own_oauth_scopes,
303 parent_oauth_scopes=parent_oauth_scopes,
304 )
305 current_scopes = (parent_oauth_scopes or []) + (own_oauth_scopes or [])
306 path_param_names = get_path_param_names(path)
307 endpoint_signature = get_typed_signature(call)
308 signature_params = endpoint_signature.parameters
309 for param_name, param in signature_params.items():
310 is_path_param = param_name in path_param_names
311 param_details = analyze_param(
312 param_name=param_name,
313 annotation=param.annotation,
314 value=param.default,
315 is_path_param=is_path_param,
316 )
317 if param_details.depends is not None:
318 assert param_details.depends.dependency
319 if (
320 (dependant.is_gen_callable or dependant.is_async_gen_callable)
321 and dependant.computed_scope == "request"
322 and param_details.depends.scope == "function"
323 ):
324 assert dependant.call
325 call_name = getattr(dependant.call, "__name__", "<unnamed_callable>")
326 raise DependencyScopeError(
327 f'The dependency "{call_name}" has a scope of '
328 '"request", it cannot depend on dependencies with scope "function".'
329 )
330 sub_own_oauth_scopes: list[str] = []
331 if isinstance(param_details.depends, params.Security):
332 if param_details.depends.scopes:
333 sub_own_oauth_scopes = list(param_details.depends.scopes)
334 sub_dependant = get_dependant(
335 path=path,
336 call=param_details.depends.dependency,
337 name=param_name,
338 own_oauth_scopes=sub_own_oauth_scopes,
339 parent_oauth_scopes=current_scopes,
340 use_cache=param_details.depends.use_cache,
341 scope=param_details.depends.scope,
342 )
343 dependant.dependencies.append(sub_dependant)

Calls 7

DependantClass · 0.90
get_path_param_namesFunction · 0.90
get_typed_signatureFunction · 0.85
analyze_paramFunction · 0.85
add_param_to_fieldsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…