(
*,
param_name: str,
annotation: Any,
value: Any,
is_path_param: bool,
)
| 391 | |
| 392 | |
| 393 | def 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: |
no test coverage detected
searching dependent graphs…