All contributions

fabiocaccamo/python-benedict

python-benedict

A Python dict subclass with key path access and built-in reading and writing of many formats, such as JSON, YAML, TOML and CSV.

Language
Python
GitHub stars
1,606
Merged changes
1

What we changed

Assigning a dict into its own nested descendant now ends in a clear ValueError instead of an uncontrolled RecursionError.

What this work shows

  • Cycle detection in recursion
  • Python dict subclasses
  • Regression tests with unittest
What was broken

A second self-assignment blew the stack

After test.a.b.c = test, a further assignment such as test.a.b.d.e = test ended in a RecursionError, and according to the issue it could crash a Jupyter kernel. _get_dict_or_value() unwrapped nested dicts recursively with no cycle detection.

How we fixed it

A cycle guard on the call stack

_get_dict_or_value() records the id() of each dict it is unwrapping and drops it on exit, so shared references are not mistaken for cycles. When it meets a dict already being unwrapped, it raises a descriptive ValueError at once, and tests also cover normal nesting and self-assignment under a new key.

#597

Merged change 1

  1. #597 Fix RecursionError when assigning a benedict into its own nested descendant (#592) Merged 29 September 2026

What it taught us

Structures that can reference themselves need cycle detection in every recursive walk. When full cycle support would mean changes in many places, a clear error at one point beats a stack overflow that can kill the process.

More about this technology: Python

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.