Repository navigation
Decode NewType int dict keys in the JSON converter - #2138
Open
devteamaegis wants to merge 1 commit into
Open
devteamaegis wants to merge 1 commit into
devteamaegis wants to merge 1 commit into
Conversation
|
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was changed
value_to_typenow unwraps aNewTypedict key type to its supertype before turning the JSON string key back into anint,float,bool,None, or int enum.Why
JSON writes every dict key as a string. The key conversion compares
key_typedirectly againstint,float,bool,NoneType, and int enums, so aNewTypeover one of those never matches. The key stays"1", and the finalvalue_to_type(UserId, "1")resolves the supertype tointand rejects the string. #1059 fixedNewTypeofstrkeys (#1032), and #1900 added int enum keys; aNewTypeover an int-like type was still missed. The default converter can encode this value but cannot decode it, so a workflow or activity with such an argument fails at decode time.Testing
ok(dict[NewIntType, str], {NewIntType(1): "1"})totest_json_type_hints. It fails without the source change and passes with it.pytest tests/test_converter.py: 42 passed. I ran it against the source tree with the published 1.36.1 bridge binary rather than a local Rust build, since the change is pure Python.NewTypekeys overfloat,bool, anIntEnum, and aNewTypeof aNewTyperound-trip.ruff check --select I,ruff format --check,pydocstyle,pyright, andbasedpyrightare clean on the touched files.mypyreports no errors in them.This was investigated and written with an AI coding agent (Claude) working on my behalf.