A subclass of `NameError` raised when handling undefined annotations during `CoreSchema` generation. Attributes: name: Name of the error. message: Description of the error.
| 103 | |
| 104 | |
| 105 | class 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 | |
| 134 | class PydanticImportError(PydanticErrorMixin, ImportError): |
no outgoing calls
no test coverage detected