MCPcopy
hub / github.com/pydantic/pydantic / _collect_metadata

Method _collect_metadata

pydantic/fields.py:671–697  ·  view source on GitHub ↗

Collect annotations from kwargs. Args: kwargs: Keyword arguments passed to the function. Returns: A list of metadata objects - a combination of `annotated_types.BaseMetadata` and `PydanticMetadata`.

(kwargs: dict[str, Any])

Source from the content-addressed store, hash-verified

669
670 @staticmethod
671 def _collect_metadata(kwargs: dict[str, Any]) -> list[Any]:
672 """Collect annotations from kwargs.
673
674 Args:
675 kwargs: Keyword arguments passed to the function.
676
677 Returns:
678 A list of metadata objects - a combination of `annotated_types.BaseMetadata` and
679 `PydanticMetadata`.
680 """
681 metadata: list[Any] = []
682 general_metadata = {}
683 for key, value in list(kwargs.items()):
684 try:
685 marker = FieldInfo.metadata_lookup[key]
686 except KeyError:
687 continue
688
689 del kwargs[key]
690 if value is not None:
691 if marker is None:
692 general_metadata[key] = value
693 else:
694 metadata.append(marker(value))
695 if general_metadata:
696 metadata.append(_fields.pydantic_general_metadata(**general_metadata))
697 return metadata
698
699 @property
700 def deprecation_message(self) -> str | None:

Callers 1

__init__Method · 0.95

Calls 1

itemsMethod · 0.45

Tested by

no test coverage detected