File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change 2323 ClassVar ,
2424 Dict ,
2525 List ,
26+ Literal ,
2627 Mapping ,
2728 NewType ,
2829 Optional ,
3940import google .protobuf .json_format
4041import google .protobuf .message
4142import google .protobuf .symbol_database
42- from typing_extensions import Literal
43+ import typing_extensions
4344
4445import temporalio .api .common .v1
4546import temporalio .api .enums .v1
@@ -1424,7 +1425,7 @@ def value_to_type(
14241425 type_args : Tuple = getattr (hint , "__args__" , ())
14251426
14261427 # Literal
1427- if origin is Literal :
1428+ if origin is Literal or origin is typing_extensions . Literal :
14281429 if value not in type_args :
14291430 raise TypeError (f"Value { value } not in literal values { type_args } " )
14301431 return value
Original file line number Diff line number Diff line change 1616 Dict ,
1717 Iterable ,
1818 List ,
19+ Literal ,
1920 Mapping ,
2021 MutableMapping ,
2122 NewType ,
3132
3233import pydantic
3334import pytest
34- from typing_extensions import Literal , TypedDict
35+ import typing_extensions
36+ from typing_extensions import TypedDict
3537
3638import temporalio .api .common .v1
3739import temporalio .common
3840from temporalio .api .common .v1 import Payload , Payloads
39- from temporalio .api .common .v1 import Payload as AnotherNameForPayload
4041from temporalio .api .failure .v1 import Failure
4142from temporalio .common import RawValue
4243from temporalio .converter import (
@@ -311,6 +312,9 @@ def fail(hint: Any, value: Any) -> None:
311312 ok (Literal ["foo" ], "foo" )
312313 ok (Literal ["foo" , False ], False )
313314 fail (Literal ["foo" , "bar" ], "baz" )
315+ ok (typing_extensions .Literal ["foo" ], "foo" )
316+ ok (typing_extensions .Literal ["foo" , False ], False )
317+ fail (typing_extensions .Literal ["foo" , "bar" ], "baz" )
314318
315319 # Dataclass
316320 ok (MyDataClass , MyDataClass ("foo" , 5 , SerializableEnum .FOO ))
You can’t perform that action at this time.
0 commit comments