Skip to content

Commit 57be463

Browse files
committed
Fix UnionType ImportError
1 parent f5f53c3 commit 57be463

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

flask_openapi3/request.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
# @Time : 2022/4/1 16:54
44
import json
55
from json import JSONDecodeError
6-
from types import UnionType
7-
from typing import Any, Type, Optional, Dict, get_origin, get_args, Union, TypeVar
6+
7+
from typing import Any, Type, Optional, Dict, get_origin, get_args, Union
8+
9+
try:
10+
from types import UnionType # Python 3.10+
11+
except ImportError:
12+
UnionType = type(Union)
813

914
from flask import request, current_app, abort
1015
from pydantic import ValidationError, BaseModel, RootModel

flask_openapi3/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
import sys
88
from enum import Enum
99
from http import HTTPStatus
10-
from types import UnionType
11-
from typing import get_type_hints, Dict, Type, Callable, List, Tuple, Optional, Any, DefaultDict
10+
11+
from typing import get_type_hints, Dict, Type, Callable, List, Tuple, Optional, Any, DefaultDict, Union
12+
13+
try:
14+
from types import UnionType # Python 3.10+
15+
except ImportError:
16+
UnionType = type(Union)
1217

1318
from flask import make_response, current_app
1419
from flask.wrappers import Response as FlaskResponse

0 commit comments

Comments
 (0)