MCPcopy
hub / github.com/fastapi/fastapi / analyze_param

Function analyze_param

fastapi/dependencies/utils.py:393–559  ·  view source on GitHub ↗
(
    *,
    param_name: str,
    annotation: Any,
    value: Any,
    is_path_param: bool,
)

Source from the content-addressed store, hash-verified

391
392
393def analyze_param(
394 *,
395 param_name: str,
396 annotation: Any,
397 value: Any,
398 is_path_param: bool,
399) -> ParamDetails:
400 field_info = None
401 depends = None
402 type_annotation: Any = Any
403 use_annotation: Any = Any
404 if is_typealiastype(annotation):
405 # unpack in case PEP 695 type syntax is used
406 annotation = annotation.__value__
407 if annotation is not inspect.Signature.empty:
408 use_annotation = annotation
409 type_annotation = annotation
410 # Extract Annotated info
411 if get_origin(use_annotation) is Annotated:
412 annotated_args = get_args(annotation)
413 type_annotation = annotated_args[0]
414 fastapi_annotations = [
415 arg
416 for arg in annotated_args[1:]
417 if isinstance(arg, (FieldInfo, params.Depends))
418 ]
419 fastapi_specific_annotations = [
420 arg
421 for arg in fastapi_annotations
422 if isinstance(
423 arg,
424 (
425 params.Param,
426 params.Body,
427 params.Depends,
428 ),
429 )
430 ]
431 if fastapi_specific_annotations:
432 fastapi_annotation: FieldInfo | params.Depends | None = (
433 fastapi_specific_annotations[-1]
434 )
435 else:
436 fastapi_annotation = None
437 # Set default for Annotated FieldInfo
438 if isinstance(fastapi_annotation, FieldInfo):
439 # Copy `field_info` because we mutate `field_info.default` below.
440 field_info = copy_field_info(
441 field_info=fastapi_annotation,
442 annotation=use_annotation,
443 )
444 assert (
445 field_info.default == Undefined or field_info.default == RequiredParam
446 ), (
447 f"`{field_info.__class__.__name__}` default value cannot be set in"
448 f" `Annotated` for {param_name!r}. Set the default value with `=` instead."
449 )
450 if value is not inspect.Signature.empty:

Callers 1

get_dependantFunction · 0.85

Calls 10

copy_field_infoFunction · 0.90
lenient_issubclassFunction · 0.90
create_model_fieldFunction · 0.90
is_scalar_fieldFunction · 0.90
ParamDetailsClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…