Skip to content

Commit dc42e88

Browse files
committed
Fix deepcopy of primitive types
1 parent a29491a commit dc42e88

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pyiceberg/types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ def __str__(self) -> str:
173173
"""Return the string representation of the PrimitiveType class."""
174174
return self.root
175175

176+
def __deepcopy__(self, memo: Dict[int, Any]) -> PrimitiveType:
177+
"""Deep copy the PrimitiveType class."""
178+
return self
179+
176180

177181
class FixedType(PrimitiveType):
178182
"""A fixed data type in Iceberg.

tests/test_types.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,3 +619,14 @@ def test_types_singleton() -> None:
619619
assert id(BooleanType()) == id(BooleanType())
620620
assert id(FixedType(22)) == id(FixedType(22))
621621
assert id(FixedType(19)) != id(FixedType(25))
622+
623+
624+
def test_deepcopy_of_singleton_fixed_type() -> None:
625+
"""FixedType is a singleton, so deepcopy should return the same instance"""
626+
from copy import deepcopy
627+
628+
list_of_fixed_types = [FixedType(22), FixedType(19)]
629+
copied_list = deepcopy(list_of_fixed_types)
630+
631+
for lhs, rhs in zip(list_of_fixed_types, copied_list):
632+
assert id(lhs) == id(rhs)

0 commit comments

Comments
 (0)