MCPcopy
hub / github.com/pydantic/pydantic / PydanticUndefinedAnnotation

Class PydanticUndefinedAnnotation

pydantic/errors.py:105–131  ·  view source on GitHub ↗

A subclass of `NameError` raised when handling undefined annotations during `CoreSchema` generation. Attributes: name: Name of the error. message: Description of the error.

Source from the content-addressed store, hash-verified

103
104
105class PydanticUndefinedAnnotation(PydanticErrorMixin, NameError):
106 """A subclass of `NameError` raised when handling undefined annotations during `CoreSchema` generation.
107
108 Attributes:
109 name: Name of the error.
110 message: Description of the error.
111 """
112
113 def __init__(self, name: str, message: str) -> None:
114 self.name = name
115 super().__init__(message=message, code='undefined-annotation')
116
117 @classmethod
118 def from_name_error(cls, name_error: NameError) -> Self:
119 """Convert a `NameError` to a `PydanticUndefinedAnnotation` error.
120
121 Args:
122 name_error: `NameError` to be converted.
123
124 Returns:
125 Converted `PydanticUndefinedAnnotation` error.
126 """
127 try:
128 name = name_error.name # type: ignore # python > 3.10
129 except AttributeError:
130 name = re.search(r".*'(.+?)'", str(name_error)).group(1) # type: ignore[union-attr]
131 return cls(name=name, message=str(name_error))
132
133
134class PydanticImportError(PydanticErrorMixin, ImportError):

Callers 2

_model_schemaMethod · 0.85
_resolve_forward_refMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected