Skip to content

Commit cd41afe

Browse files
committed
Handle Python 3.9
1 parent d9a475a commit cd41afe

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pydantic2ts/cli/script.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111
from inspect import isclass
1212
from pathlib import Path
1313
from tempfile import mkdtemp
14-
from types import ModuleType, UnionType
14+
from types import ModuleType
1515
from typing import Any, Dict, List, Tuple, Type, Union
1616
from typing_extensions import get_args, get_origin
1717
from uuid import uuid4
1818

1919
from pydantic import VERSION, BaseModel, create_model
2020

21+
try:
22+
from types import UnionType
23+
except ImportError:
24+
UnionType = None
25+
2126
V2 = True if VERSION.startswith("2") else False
2227

2328
if not V2:
@@ -186,7 +191,7 @@ def extend_enum_definitions(
186191
if is_matching_enum(inner_type, schema["title"]):
187192
add_ts_enum_names(schema, inner_type)
188193
break
189-
elif origin is UnionType or origin is Union:
194+
elif (UnionType and origin is UnionType) or origin is Union:
190195
for inner_type in get_args(prop_type):
191196
if is_matching_enum(inner_type, schema["title"]):
192197
add_ts_enum_names(schema, inner_type)

0 commit comments

Comments
 (0)