Skip to content

Commit 35347b9

Browse files
Fix: Resolve TypeError in value_to_type on Python 3.13 (issue #1188) (#1189)
* Fix: Resolve TypeError in value_to_type on Python 3.13 (issue #1188) * fix poe linting * replace newtype check '#1189 (comment)' --------- Co-authored-by: tconley1428 <[email protected]>
1 parent 660ac2b commit 35347b9

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

temporalio/converter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,9 +1764,7 @@ def value_to_type(
17641764
elif key_type is type(None):
17651765
key = {"null": None}[key]
17661766

1767-
# Can't call isinstance if key_type is a newtype
1768-
is_newtype = getattr(key_type, "__supertype__", None)
1769-
if is_newtype or not isinstance(key, key_type):
1767+
if not isinstance(key_type, type) or not isinstance(key, key_type):
17701768
key = value_to_type(key_type, key, custom_converters)
17711769
except Exception as err:
17721770
raise TypeError(

tests/test_converter.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,3 +671,29 @@ async def test_json_type_converter():
671671
assert [addr, addr] == (
672672
await custom_conv.decode([list_payload], [List[ipaddress.IPv4Address]])
673673
)[0]
674+
675+
676+
def test_value_to_type_literal_key():
677+
# The type for the dictionary's *key*:
678+
KeyHint = Literal[
679+
"Key1",
680+
"Key2",
681+
]
682+
683+
# The type for the dictionary's *value* (the inner dict):
684+
InnerKeyHint = Literal[
685+
"Inner1",
686+
"Inner2",
687+
]
688+
InnerValueHint = str | int | float | None
689+
ValueHint = dict[InnerKeyHint, InnerValueHint]
690+
691+
# The full type hint for the mapping:
692+
hint_with_bug = dict[KeyHint, ValueHint]
693+
694+
# A value that uses one of the literal keys:
695+
value_to_convert = {"Key1": {"Inner1": 123.45, "Inner2": 10}}
696+
custom_converters: Sequence[JSONTypeConverter] = []
697+
698+
# Function executes without error
699+
value_to_type(hint_with_bug, value_to_convert, custom_converters)

0 commit comments

Comments
 (0)