Skip to content

Commit 7853511

Browse files
committed
Avoid DeprecationWarning when importing OrderedDict
in flask_restx/model.py and flask_restx/swagger.py logic is installed to circumvent differences in Python2 and Python3 when importing from the collections module. Some classes from collections has been moved to collections.abc in Python3. OrderedDict is not one of them, hence an ImportError is raised when trying to import OrderedDict from collections.abc. This then leads to importing both OrderedDict AND MutableMapping/Hashable from collections.abc which then raises a deprecation warning since MutableMapping/Hashable lives in collections.abc in Python3. This patch should fix those DeprecationWarnings to be raised.
1 parent ae9aa33 commit 7853511

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

flask_restx/model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
import re
66
import warnings
77

8+
from collections import OrderedDict
89
try:
9-
from collections.abc import OrderedDict, MutableMapping
10+
from collections.abc import MutableMapping
1011
except ImportError:
1112
# TODO Remove this to drop Python2 support
12-
from collections import OrderedDict, MutableMapping
13+
from collections import MutableMapping
1314
from six import iteritems, itervalues
1415
from werkzeug.utils import cached_property
1516

flask_restx/swagger.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
import re
66

77
from inspect import isclass, getdoc
8+
from collections import OrderedDict
89
try:
9-
from collections.abc import OrderedDict, Hashable
10+
from collections.abc import Hashable
1011
except ImportError:
1112
# TODO Remove this to drop Python2 support
12-
from collections import OrderedDict, Hashable
13+
from collections import Hashable
1314
from six import string_types, itervalues, iteritems, iterkeys
1415

1516
from flask import current_app

0 commit comments

Comments
 (0)