diff --git a/temporalio/converter.py b/temporalio/converter.py index 29eb35566..92a5d72e2 100644 --- a/temporalio/converter.py +++ b/temporalio/converter.py @@ -1764,9 +1764,7 @@ def value_to_type( elif key_type is type(None): key = {"null": None}[key] - # Can't call isinstance if key_type is a newtype - is_newtype = getattr(key_type, "__supertype__", None) - if is_newtype or not isinstance(key, key_type): + if not isinstance(key_type, type) or not isinstance(key, key_type): key = value_to_type(key_type, key, custom_converters) except Exception as err: raise TypeError( diff --git a/tests/test_converter.py b/tests/test_converter.py index e274b10d9..a6a292dff 100644 --- a/tests/test_converter.py +++ b/tests/test_converter.py @@ -671,3 +671,29 @@ async def test_json_type_converter(): assert [addr, addr] == ( await custom_conv.decode([list_payload], [List[ipaddress.IPv4Address]]) )[0] + + +def test_value_to_type_literal_key(): + # The type for the dictionary's *key*: + KeyHint = Literal[ + "Key1", + "Key2", + ] + + # The type for the dictionary's *value* (the inner dict): + InnerKeyHint = Literal[ + "Inner1", + "Inner2", + ] + InnerValueHint = str | int | float | None + ValueHint = dict[InnerKeyHint, InnerValueHint] + + # The full type hint for the mapping: + hint_with_bug = dict[KeyHint, ValueHint] + + # A value that uses one of the literal keys: + value_to_convert = {"Key1": {"Inner1": 123.45, "Inner2": 10}} + custom_converters: Sequence[JSONTypeConverter] = [] + + # Function executes without error + value_to_type(hint_with_bug, value_to_convert, custom_converters)