Skip to content

Preserve empty-string parent keys when flattening - #644

Open
UmutAlisoglu wants to merge 1 commit into
fabiocaccamo:mainfrom
UmutAlisoglu:codex/flatten-empty-parent-keys
Open

UmutAlisoglu wants to merge 1 commit into
fabiocaccamo:mainfrom
UmutAlisoglu:codex/flatten-empty-parent-keys

Conversation

@UmutAlisoglu

Copy link
Copy Markdown

Describe your changes

An empty-string parent key is treated as the root prefix during flattening. This loses part of the path and can raise a false conflict:

benedict({"": {"child": 1}, "child": 2}).flatten()
# before: KeyError for 'child'
# after: {'_child': 1, 'child': 2}

Use None as the internal root-prefix sentinel so an actual empty-string key still contributes a separator. Extend the existing falsy-parent tests and add a public round trip covering nested empty keys, indexed lists and custom separators. Source data stays unchanged.

Related issue

No matching issue or PR found. This follows the falsy-parent fix in #600, whose scope explicitly left empty-string behavior unchanged. The reproduction above demonstrates the remaining case.

Validation

  • Original source with the four affected test methods: 3 failing assertions and 5 errors, all in the new empty-key subcases.
  • Windows / Python 3.14.7: full suite, 991 tests passed. S3 credentials were empty, so no real S3 operations are claimed.
  • After final formatting: focused flatten/unflatten/public API suite, 114 tests passed; flatten.py has 100% line and branch coverage.
  • Strict mypy passes on all 65 package files.
  • All applicable pinned pre-commit hooks pass on the changed files.

Checklist before requesting a review

  • I have performed a self-review of my code. (AI-assisted review; no human review claimed.)
  • I have added tests for the proposed changes.
  • I have run the tests and there are not errors.

AI assistance: OpenAI Codex assisted with investigation, implementation, review and verification.

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.

1 participant