Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix to_builtins with frozendict - #1105

Merged
sobolevn merged 3 commits into
msgspec:mainfrom
sobolevn:issue-1104
Jul 2, 2026
Merged

Fix to_builtins with frozendict#1105
sobolevn merged 3 commits into
msgspec:mainfrom
sobolevn:issue-1104

Conversation

@sobolevn

@sobolevn sobolevn commented Jul 1, 2026

Copy link
Copy Markdown
Member

Now it follows the same rules as dict :)

  1. Converts nested elements
  2. Respects order keyword

Closes #1104

@codspeed-hq

codspeed-hq Bot commented Jul 1, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 139 untouched benchmarks
⏩ 135 skipped benchmarks1


Comparing sobolevn:issue-1104 (c415ff8) with main (68f53a7)

Open in CodSpeed

Footnotes

  1. 135 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Siyet
Siyet previously approved these changes Jul 2, 2026

@Siyet Siyet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the quick follow-up! Did a deep pass on 5a54d59 including an empirical run on 3.15.0a7.

Verified:

  • The #1104 repro is fixed: enum keys/values and nested frozendicts convert in both modes, str_keys and order are honored now, plain-dict parity holds for content and ordering in all three order modes, and the type is preserved only with builtin_types=(frozendict,) - matching the flag's intent from #1052.
  • Refcounting is clean on every path: _PyFrozenDict_NewSteal's NULL-guard covers the to_builtins_dict error paths (enc_hook raise, unsortable keys with order, str_keys TypeError), and 100k-300k iteration loops over both happy and error paths show zero RSS/gc-object growth.
  • No dict-path regression (byte-identical behavior for plain dict, with and without the flag), encoders/convert untouched as they should be, builds and full suite green on 3.12 (PY315_PLUS off) and 3.15, including the PR diff re-applied onto current main.

Three small notes, none blocking:

  1. In test_frozendict_builtin_types_sorted the assert_eq helper only checks ordering under if isinstance(left, typ) - if the fix ever regressed to returning a plain dict, equality would still pass (frozendict == dict) and the order check would silently skip, so the test would stay green without testing anything. An assert isinstance(left, typ) (or a type(res) is frozendict pin in the test) closes that - same lesson as the test_order_frozendict fix in #1107.
  2. The PR body has no Closes #1104, so the issue won't auto-close on merge - worth adding.
  3. Optional: one test line for a frozendict subclass input (it now collapses to exact frozendict/dict, consistent with dict-subclass behavior, but nothing pins that).

@sobolevn

sobolevn commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

I've updated tests and will merge it once CI passes.

@sobolevn

sobolevn commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

@Siyet thanks a lot for your review! Really helpful.

@sobolevn
sobolevn added this pull request to the merge queue Jul 2, 2026
Merged via the queue into msgspec:main with commit 903a340 Jul 2, 2026
27 checks passed
@sobolevn
sobolevn deleted the issue-1104 branch July 2, 2026 17:23
pull Bot pushed a commit to Future-Outlier/msgspec that referenced this pull request Jul 3, 2026
Batches the changelog entries accumulated since the 0.21.1 release,
following the usual pre-release batching practice (like msgspec#1020). Covers
merged user-facing changes through msgspec#1109/msgspec#978/msgspec#1105; internal
CI/benchmarking/test-infra changes are intentionally omitted. Also
records the move to the msgspec GitHub organization.

---------

Co-authored-by: Siyet <[email protected]>
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.

Incorrect to_builtins convertion with builtin_types=(frozendict,)

2 participants