Skip to content

Deep-copy dictionary keys with the value memo - #641

Open
hakarrr wants to merge 3 commits into
fabiocaccamo:mainfrom
hakarrr:fix-deepcopy-keys
Open

hakarrr wants to merge 3 commits into
fabiocaccamo:mainfrom
hakarrr:fix-deepcopy-keys

Conversation

@hakarrr

@hakarrr hakarrr commented Oct 24, 2026

Copy link
Copy Markdown

Fixes #640.

Both deepcopy implementations copied values but reused the original keys. For a custom hashable object used as both a key and a value, this retained a reference to the original key and broke the key/value alias in the copy.

Deep-copy keys with the same memo used for values, matching dict deepcopy behavior. Two regression methods cover wrapped/unwrapped BaseDict instances, frozen instances, key/value aliases, mutation independence, and benedict's custom keypath/keyattr settings. Cyclic mapping rejection is unchanged.

Validation on Linux:

  • Untouched main: 990 tests pass in a credential-free environment.
  • New regression on unchanged production code: all 8 subtests fail.
  • Final code: all 992 tests pass on CPython 3.11.17 and 3.12.15.
  • Python 3.12 combined line/branch coverage: 98%.
  • All pre-commit hooks pass, including Ruff and mypy. Standalone mypy passes all 65 source files on both baseline and final code.
  • Wheel/sdist builds and diff whitespace check pass.

Real S3 integration tests use their existing no-credentials early-return path, as on upstream CI; mocked S3 tests still run. Real AWS operations were not verified. Python 3.13-3.15, PyPy, and other operating systems were not run. No existing tests or CI configuration were changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deepcopy retains original custom keys and breaks key/value aliases

1 participant