Skip to content

Commit 013b711

Browse files
committed
fix compat for types.UnionType
1 parent 8975251 commit 013b711

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

utype/parser/rule.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import inspect
21
import re
3-
import types
42
import typing
53
import warnings
64
from collections import deque
@@ -12,7 +10,7 @@
1210

1311
from ..utils import exceptions as exc
1412
from ..utils.compat import (ForwardRef, Literal, evaluate_forward_ref,
15-
get_args, get_origin)
13+
get_args, get_origin, UnionType)
1614
from ..utils.datastructures import unprovided
1715
from ..utils.functional import multi, pop
1816
from ..utils.transform import TypeTransformer
@@ -1308,7 +1306,7 @@ def annotate(
13081306
# return type_
13091307

13101308
name = cls.__name__
1311-
if type_ == Union or type_ == types.UnionType:
1309+
if type_ == Union or type_ == UnionType:
13121310
# in Python >= 3.10, native logic operator like int | str will be a UnionType
13131311
type_ = LogicalType.any_of(*args)
13141312
# clear the args for union

utype/utils/compat.py

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
except ImportError:
1212
from typing_extensions import Literal
1313

14+
try:
15+
from types import UnionType
16+
except ImportError:
17+
UnionType = Union
18+
1419
try:
1520
from typing import Final
1621
except ImportError:
@@ -27,6 +32,7 @@
2732
"get_args",
2833
'Literal',
2934
'Final',
35+
'UnionType',
3036
"ForwardRef",
3137
"Annotated",
3238
"is_final",

0 commit comments

Comments
 (0)