Skip to content

Commit df43173

Browse files
committed
Fix: Resolve TypeError in value_to_type on Python 3.13 (issue #1188)
1 parent 27903f7 commit df43173

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

temporalio/converter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,11 @@ def value_to_type(
17661766

17671767
# Can't call isinstance if key_type is a newtype
17681768
is_newtype = getattr(key_type, "__supertype__", None)
1769-
if is_newtype or not isinstance(key, key_type):
1769+
if (
1770+
is_newtype
1771+
or not isinstance(key_type, type)
1772+
or not isinstance(key, key_type)
1773+
):
17701774
key = value_to_type(key_type, key, custom_converters)
17711775
except Exception as err:
17721776
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 = []
697+
698+
# Function executes without error
699+
value_to_type(hint_with_bug, value_to_convert, custom_converters)

0 commit comments

Comments
 (0)