MCPcopy
hub / github.com/pydantic/pydantic / rebuild_annotation

Method rebuild_annotation

pydantic/fields.py:754–771  ·  view source on GitHub ↗

Attempts to rebuild the original annotation for use in function signatures. If metadata is present, it adds it to the original annotation using `Annotated`. Otherwise, it returns the original annotation as-is. Note that because the metadata has been flattened, the original

(self)

Source from the content-addressed store, hash-verified

752 return self.default is PydanticUndefined and self.default_factory is None
753
754 def rebuild_annotation(self) -> Any:
755 """Attempts to rebuild the original annotation for use in function signatures.
756
757 If metadata is present, it adds it to the original annotation using
758 `Annotated`. Otherwise, it returns the original annotation as-is.
759
760 Note that because the metadata has been flattened, the original annotation
761 may not be reconstructed exactly as originally provided, e.g. if the original
762 type had unrecognized annotations, or was annotated with a call to `pydantic.Field`.
763
764 Returns:
765 The rebuilt annotation.
766 """
767 if not self.metadata:
768 return self.annotation
769 else:
770 # Annotated arguments must be a tuple
771 return Annotated[(self.annotation, *self.metadata)] # type: ignore
772
773 def apply_typevars_map(
774 self,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected