Return a copy of the `FieldInfo` instance.
(self)
| 814 | } |
| 815 | |
| 816 | def _copy(self) -> Self: |
| 817 | """Return a copy of the `FieldInfo` instance.""" |
| 818 | # Note: we can't define a custom `__copy__()`, as `FieldInfo` is being subclassed |
| 819 | # by some third-party libraries with extra attributes defined (and as `FieldInfo` |
| 820 | # is slotted, we can't make a copy of the `__dict__`). |
| 821 | if type(self) is FieldInfo: |
| 822 | # Fast-path if the instance isn't a subclass (`copy.copy()` relies on pickling which is slower): |
| 823 | copied = FieldInfo.__new__(FieldInfo) |
| 824 | for attr_name in FieldInfo.__slots__: |
| 825 | setattr(copied, attr_name, getattr(self, attr_name)) |
| 826 | else: |
| 827 | copied = copy(self) |
| 828 | |
| 829 | for attr_name in ('metadata', '_attributes_set', '_qualifiers'): |
| 830 | # Apply "deep-copy" behavior on collections attributes: |
| 831 | setattr(copied, attr_name, getattr(copied, attr_name).copy()) |
| 832 | |
| 833 | return copied # pyright: ignore[reportReturnType] |
| 834 | |
| 835 | def __repr_args__(self) -> ReprArgs: |
| 836 | yield 'annotation', _repr.PlainRepr(_repr.display_as_type(self.annotation)) |
no test coverage detected