Skip to content

Fix JSON conversion for dict[None, T] keys#1677

Open
hsusul wants to merge 1 commit into
temporalio:mainfrom
hsusul:fix-dict-none-key-conversion
Open

Fix JSON conversion for dict[None, T] keys#1677
hsusul wants to merge 1 commit into
temporalio:mainfrom
hsusul:fix-dict-none-key-conversion

Conversation

@hsusul

@hsusul hsusul commented Jul 26, 2026

Copy link
Copy Markdown

Summary

Normalize the literal None key argument produced by built-in
dict[None, T] type hints so JSON object keys serialized as "null" are
restored to Python None.

Fixes #1237.

Root cause

Built-in generics and typing.Dict expose this annotation differently:

  • dict[None, str] yields literal None as its key argument
  • typing.Dict[None, str] yields NoneType

The mapping converter treated literal None as an absent key type, so it left
the JSON key as "null".

The normalization is intentionally mapping-specific. It does not alter unrelated
annotations such as Literal[None].

Changes

  • normalize literal None to NoneType while selecting a mapping key converter
  • update the existing known-bug assertion to expect {None: "1"}
  • add an Unreleased changelog entry

Validation

  • focused test_json_type_hints
  • complete tests/test_converter.py: 28 passed
  • repository-wide poe lint
  • git diff --check

@hsusul
hsusul requested a review from a team as a code owner July 26, 2026 01:47
@CLAassistant

CLAassistant commented Jul 26, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

[Bug] Converter returns bad value converting dict[None, Any]

2 participants