Skip to content

Honor freezing when deleting or popping a keypath from a benedict instance - #635

Merged
fabiocaccamo merged 2 commits into
fabiocaccamo:mainfrom
helo060228:fix/frozen-keypath-deletion
Oct 20, 2026
Merged

fabiocaccamo merged 2 commits into
fabiocaccamo:mainfrom
helo060228:fix/frozen-keypath-deletion

Conversation

@helo060228

Copy link
Copy Markdown
Contributor

Describe your changes

A frozen benedict rejects d["a.b"] = 2, but del d["a.b"] and d.pop("a.b") still remove the nested value. Keypath deletion resolves a nested parent and operates on it without reaching the root frozen check.

Check the root state in benedict.__delitem__ and benedict.pop, alongside the existing benedict.__setitem__ check. The production change adds five lines. Directly obtained nested dictionaries and lists remain mutable, as documented for shallow freeze. The lower-level keylist/keypath classes retain their existing behavior.

Five test methods cover dotted paths, keylists, list indexes, custom separators, pop with omitted/None/explicit defaults, missing paths, unfrozen and unfrozen-again instances, and direct child mutation. Add one Unreleased changelog entry.

Related issue

Fixes #634

Validation

  • Base commit c4c8a58d517b4ceaa21b6d7529afe1527446100e.
  • Unmodified source: python -m unittest — 963 tests ran.
  • New tests against unmodified source: 25 freeze test methods ran, with 38 failing subcases across three new methods (24 pop keypath, 8 del keypath, 6 missing keypath with default). Mutable and direct-child controls passed.
  • Patched source: python -m unittest tests.dicts.test_benedict_freeze — 25 tests passed.
  • Patched source: python -m unittest — 968 tests ran.
  • All applicable pinned pre-commit hooks passed for the changed files, including Mypy 2.4.0. check-yaml had no matching files.
  • python -m mypy benedict (Mypy 2.3.1) — no issues in 65 source files. git diff --check passed.

Environment: Windows CPython 3.13.5; an earlier run on Linux CPython 3.12.14 produced the same test counts and the same failure breakdown. A few IO tests that fetch fixtures over the network were skipped by transport errors in both runs and are unrelated to this change.

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have added tests for the proposed changes.
  • I have run the tests and there are not errors.

Disclosure: developed, tested, and self-reviewed with Codex. No human or independent agent review is claimed.

@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.69%. Comparing base (c4c8a58) to head (edd4218).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #635   +/-   ##
=======================================
  Coverage   98.69%   98.69%           
=======================================
  Files          65       65           
  Lines        2446     2450    +4     
=======================================
+ Hits         2414     2418    +4     
  Misses         32       32           
Flag Coverage Δ
unittests 98.69% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fabiocaccamo
fabiocaccamo merged commit ab33d13 into fabiocaccamo:main Oct 20, 2026
18 checks passed
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.

Frozen benedict allows deleting nested keys through root keypath APIs

2 participants