Skip to content

Commit 9c59454

Browse files
committed
3.7 fixes
1 parent e61a1a6 commit 9c59454

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

temporalio/converter.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
Dict,
2020
Iterable,
2121
List,
22-
Literal,
2322
Mapping,
24-
NewType,
2523
Optional,
2624
Tuple,
2725
Type,
@@ -32,6 +30,7 @@
3230
import google.protobuf.json_format
3331
import google.protobuf.message
3432
import google.protobuf.symbol_database
33+
from typing_extensions import Literal
3534

3635
import temporalio.api.common.v1
3736
import temporalio.common
@@ -845,9 +844,12 @@ def value_to_type(hint: Type, value: Any) -> Any:
845844
raise TypeError(f"Expected None, got value of type {type(value)}")
846845
return None
847846

848-
# NewType
849-
if isinstance(hint, NewType):
850-
return value_to_type(hint.__supertype__, value)
847+
# NewType. Note we cannot simply check isinstance NewType here because it's
848+
# only been a class since 3.10. Instead we'll just check for the presence
849+
# of a supertype.
850+
supertype = getattr(hint, "__supertype__", None)
851+
if supertype:
852+
return value_to_type(supertype, value)
851853

852854
# Load origin for other checks
853855
origin = getattr(hint, "__origin__", hint)

tests/test_converter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
Dict,
1313
Iterable,
1414
List,
15-
Literal,
1615
Mapping,
1716
MutableMapping,
1817
NewType,
@@ -27,7 +26,7 @@
2726

2827
import pydantic
2928
import pytest
30-
from typing_extensions import TypedDict
29+
from typing_extensions import Literal, TypedDict
3130

3231
import temporalio.api.common.v1
3332
import temporalio.common

0 commit comments

Comments
 (0)