As John Gordon pointed out in the comments, this has nothing to do with deepcopy. Looks like your Python implementation re-uses the same object for equal tuples of literals, no matter where they appear. As in:
a = (1, 2, 3)
b = (1, 2, 3)
a is b # True
This is an implementation detail that you cannot rely on. In CPython, the most common implementation, that line used to evaluate to False
. Nobody guarantees that it won't return False
again next year. I plugged the same into an online interpreter that relies on the Skulpt implementation and it returns False too (code).
Just use ==
for comparison!
Why does CPython store equal tuples in the same memory location? I can only speculate but it's probably to conserve memory.