Skip to content

Commit 5dae4e0

Browse files
committed
gh-161524: Preserve noncompact copy test rationale
1 parent d0c69f8 commit 5dae4e0

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎Lib/test/test_dict.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,14 @@ class A:
466466
self.assertEqual(gc.is_tracked(d), gc.is_tracked(d2))
467467

468468
def test_copy_noncompact(self):
469-
# Deletions leave holes in the entry table. Copying a sparse
470-
# dictionary must preserve its contents and compact the table.
469+
# Dicts don't compact themselves on del/pop operations.
470+
# Copy uses a slow merging strategy that produces a
471+
# compacted copy when fewer than about 1/64 of the original
472+
# entries remain (to avoid scanning mostly deleted entries).
473+
# In this test we want to hit the slow/compacting
474+
# branch of dict.copy() and make sure it works OK.
471475
d = {k: k for k in range(1000)}
472-
for k in range(950):
476+
for k in range(999):
473477
del d[k]
474478
d2 = d.copy()
475479
self.assertEqual(d2, d)

0 commit comments

Comments
 (0)