Returns a deep copy of the model.
(self, memo: dict[int, Any] | None = None)
| 988 | return m |
| 989 | |
| 990 | def __deepcopy__(self, memo: dict[int, Any] | None = None) -> Self: |
| 991 | """Returns a deep copy of the model.""" |
| 992 | cls = type(self) |
| 993 | m = cls.__new__(cls) |
| 994 | _object_setattr(m, '__dict__', deepcopy(self.__dict__, memo=memo)) |
| 995 | _object_setattr(m, '__pydantic_extra__', deepcopy(self.__pydantic_extra__, memo=memo)) |
| 996 | # This next line doesn't need a deepcopy because __pydantic_fields_set__ is a set[str], |
| 997 | # and attempting a deepcopy would be marginally slower. |
| 998 | _object_setattr(m, '__pydantic_fields_set__', copy(self.__pydantic_fields_set__)) |
| 999 | |
| 1000 | if not hasattr(self, '__pydantic_private__') or self.__pydantic_private__ is None: |
| 1001 | _object_setattr(m, '__pydantic_private__', None) |
| 1002 | else: |
| 1003 | _object_setattr( |
| 1004 | m, |
| 1005 | '__pydantic_private__', |
| 1006 | deepcopy({k: v for k, v in self.__pydantic_private__.items() if v is not PydanticUndefined}, memo=memo), |
| 1007 | ) |
| 1008 | |
| 1009 | return m |
| 1010 | |
| 1011 | if not TYPE_CHECKING: |
| 1012 | # We put `__getattr__` in a non-TYPE_CHECKING block because otherwise, mypy allows arbitrary attribute access |
no test coverage detected