Frozen benedict allows deleting nested keys through root keypath APIs
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 62/100
Research direction
Start with the existing frozen check on keypath assignment in the public benedict class, then trace how del, pop and the keylist path reach KeylistDict and BaseDict, which skip that check. Reproduce with the two snippets in the report and read test_freeze_prevents_setitem_keypath as the model for a new test. Done means deletion and pop on a frozen root raise TypeError and leave contents unchanged, while a separately obtained child stays mutable.
Written by the indexing model from the issue text.
Description
Python version
CPython 3.12.14 on Linux.
Package version
0.40.0, reproduced from main at c4c8a58d517b4ceaa21b6d7529afe1527446100e.
Current behavior (bug description)
Root keypath assignment on a frozen benedict raises TypeError, but deletion and pop through the same root object still remove nested values:
from benedict import benedict
d = benedict({"a": {"b": 1}}).freeze()
del d["a.b"]
print(d) # {'a': {}}
d = benedict({"a": {"b": 1}}).freeze()
print(d.pop("a.b")) # 1
print(d) # {'a': {}}
By comparison, benedict({"a": {"b": 1}}).freeze()["a.b"] = 2 raises TypeError. That behavior is already covered by test_freeze_prevents_setitem_keypath from the original freeze implementation.
The same deletion inconsistency occurs with keylists, list indexes such as values[0], and a custom keypath separator.
Expected behavior
Deletion and pop invoked on a frozen root benedict should check that object's frozen state, consistently with its existing keypath assignment behavior. A failed operation should leave its contents unchanged. pop with a default should follow the same rule as the existing top-level frozen pop behavior.
The documented shallow freeze remains useful: a separately obtained child such as d["a"] should remain mutable. This report concerns the root keypath API; it does not request recursively frozen children.
KeylistDict resolves the nested parent and deletes or pops directly from it, so the root BaseDict check is skipped. Checking at the public benedict layer, where the keypath assignment check already lives, would keep the change limited to this API.
Related #613/#614 concern deriving new dictionaries from a frozen source, rather than deleting values from it.
Disclosure: reproduced and investigated with Codex. No human review is claimed.
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 63
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 21
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fabiocaccamo/python-benedict
-
Take over the BeneDict name on PyPIMay be free again @fabiocaccamo claimed this 693 days ago, and no pull request is open. Openenhancement
fabiocaccamo/python-benedict#458 · 2 comments · 2 reactions · 1 assignee ·
Maintainers usually reply within 2 days
-
Add possibility to use `requests-html` when calling `from_html` method.May be free again @fabiocaccamo claimed this 827 days ago, and no pull request is open. Openenhancement
fabiocaccamo/python-benedict#425 · 1 assignee ·
Maintainers usually reply within 2 days
-
Wildcard support for renamingPossibly taken @fabiocaccamo claimed this 1494 days ago. Openenhancement
fabiocaccamo/python-benedict#113 · 12 comments · 1 reaction · 1 assignee ·
Maintainers usually reply within 2 days
-
Add `xpath` support.May be free again @fabiocaccamo claimed this 1839 days ago, and no pull request is open. Openenhancement
fabiocaccamo/python-benedict#67 · 3 comments · 1 assignee ·
Maintainers usually reply within 2 days
All issues in fabiocaccamo/python-benedict
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
huggingface/sentence-transformers#4186 ·
Maintainers usually reply within 5 days
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 92/100
QuantEcon/QuantEcon.py#988 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
fabriziosalmi/certmate#1247 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
documentation good first issue
Difficulty 2/5 Half a day Newbie friendliness 72/100
sujithputta02/Esapay#13 ·