-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Description
Tests enhancement
Currently there are two tests in Lib/test/test_copy.py that inspect memo's internal structure directly:
test_deepcopy_keepalive:
Line 440 in 598d4c6
| self.assertIs(memo[id(memo)][0], x) |
test_deepcopy_dont_memo_immutable:Lines 447 to 448 in 598d4c6
| # There's the entry for the new list, and the keep alive. | |
| self.assertEqual(len(memo), 2) |
This constrains implementations to maintain that specific structure, creating friction for both improvements to Lib/copy.py and alternative implementations aiming to pass the test suite.
Docs explicitly state:
object.__deepcopy__(self, memo)..., it should call the
deepcopy()function with the component as first argument and the memo dictionary as second argument. The memo dictionary should be treated as an opaque object.
Proposal
I propose rewriting these tests to verify observable behavior rather than internal structure.
This will make tests somewhat less straightforward, but will solidify what deepcopy actually guarantees in terms of externally observable effects, without relying on implementation details.
No changes to Lib/copy.py are proposed.