Skip to content

Commit bc3dcf0

Browse files
committed
fix typing issue with UnionType in py3.9
Signed-off-by: Filinto Duran <[email protected]>
1 parent 5e1bab3 commit bc3dcf0

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

dapr/clients/grpc/_conversation_helpers.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import string
1919
from dataclasses import fields, is_dataclass
2020
from enum import Enum
21-
from types import UnionType
2221
from typing import (
2322
Any,
2423
Callable,
@@ -37,6 +36,12 @@
3736

3837
from dapr.conf import settings
3938

39+
import types
40+
41+
# Make mypy happy. Runtime handle: real class on 3.10+, else None.
42+
# TODO: Python 3.9 is about to be end-of-life, so we can drop this at some point next year (2026)
43+
UnionType: Any = getattr(types, 'UnionType', None)
44+
4045
# duplicated from conversation to avoid circular import
4146
Params = Union[Mapping[str, Any], Sequence[Any], None]
4247

@@ -857,7 +862,9 @@ def _coerce_literal(value: Any, lit_args: List[Any]) -> Any:
857862

858863
def _is_union(t) -> bool:
859864
origin = get_origin(t)
860-
return origin in (Union, UnionType) # handles 3.8–3.13+
865+
if origin is Union:
866+
return True
867+
return UnionType is not None and origin is UnionType
861868

862869

863870
def _coerce_and_validate(value: Any, expected_type: Any) -> Any:

0 commit comments

Comments
 (0)