Tests enhancement
Currently there are two tests in Lib/test/test_copy.py that inspect memo's internal structure directly:
test_deepcopy_keepalive:
|
self.assertIs(memo[id(memo)][0], x) |
test_deepcopy_dont_memo_immutable:
|
# 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:
..., 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.
Linked PRs
Tests enhancement
Currently there are two tests in
Lib/test/test_copy.pythat inspect memo's internal structure directly:test_deepcopy_keepalive:cpython/Lib/test/test_copy.py
Line 440 in 598d4c6
test_deepcopy_dont_memo_immutable:cpython/Lib/test/test_copy.py
Lines 447 to 448 in 598d4c6
This constrains implementations to maintain that specific structure, creating friction for both improvements to
Lib/copy.pyand alternative implementations aiming to pass the test suite.Docs explicitly state:
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.pyare proposed.Linked PRs
test_deepcopy_keepaliveand_dont_memo_immutable#142255@cpython_onlyto tests relying on deepcopy implementation #142324