Skip to content

Commit a0933bc

Browse files
committed
Test Constants.copy() preserves subclass type
copy() is deepcopy-based (restored via __getstate__/__setstate__, not by re-invoking type(self)(...)), so a naive reimplementation could silently downgrade a subclass instance to plain Constants with no existing test catching it. Found in review of #282.
1 parent 310a793 commit a0933bc

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

tests/test_constants.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,17 @@ def test_copy_is_not_the_same_object(self) -> None:
986986
self.assertIsNot(dup, c)
987987
self.assertTrue(isinstance(dup, Constants))
988988

989+
def test_copy_preserves_subclass_type(self) -> None:
990+
# copy() is deepcopy-based (restored via __getstate__/__setstate__,
991+
# not by re-invoking type(self)(...)), so a naive reimplementation
992+
# could silently downgrade a subclass instance to plain Constants.
993+
class CustomConstants(Constants):
994+
pass
995+
996+
c = CustomConstants()
997+
dup = c.copy()
998+
self.assertTrue(isinstance(dup, CustomConstants))
999+
9891000
def test_copy_snapshots_current_customizations(self) -> None:
9901001
# Unlike Constants(), which always starts from library defaults,
9911002
# .copy() preserves whatever customizations the original already has.

0 commit comments

Comments
 (0)