Skip to content

Stringify orjson mapping keys after unstructure hooks - #792

Open
adenzhou1350 wants to merge 1 commit into
python-attrs:mainfrom
adenzhou1350:codex/fix-orjson-mapping-key-coercion
Open

adenzhou1350 wants to merge 1 commit into
python-attrs:mainfrom
adenzhou1350:codex/fix-orjson-mapping-key-coercion

Conversation

@adenzhou1350

Copy link
Copy Markdown

The orjson converter promises to coerce mapping keys to strings, but a non-identity unstructure hook replaces that coercion. Passthrough hooks for Union[str, int] and Any can consequently leave integer keys, and dumps() raises TypeError: Dict key must be str.

Compose str() after the selected key hook. This retains custom hooks and base85 bytes conversion; the special string-enum branch is unchanged.

Add regressions for Union/PEP 604/Any/int keys, an attrs field, string enums, bytes, and custom hooks returning either integers or strings. Update HISTORY.

Validation:

  • Unchanged baseline: 8 of the 13 new cases fail on Windows and Linux.
  • Windows CPython 3.12: 25 relevant tests pass, including a fresh pre-publication rerun.
  • Linux CPython 3.12: 80 relevant tests pass, 8 optional-backend tests skip; Ruff check and format pass.

The complete supported-Python matrix has not been run locally. This does not add lossless key round-tripping or collision handling.

AI-assisted implementation; the human submitter reviewed the complete patch and approved submission.

Signed-off-by: Xucheng Zhou <aden1350@outlook.com>

This branch has not been deployed

No deployments
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