Skip to content

Commit

Permalink
Avoid DeprecationWarning when importing OrderedDict
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kbevers committed Feb 12, 2020
1 parent ae9aa33 commit 7853511
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions flask_restx/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import re
import warnings

from collections import OrderedDict
try:
from collections.abc import OrderedDict, MutableMapping
from collections.abc import MutableMapping
except ImportError:
# TODO Remove this to drop Python2 support
from collections import OrderedDict, MutableMapping
from collections import MutableMapping
from six import iteritems, itervalues
from werkzeug.utils import cached_property

Expand Down
5 changes: 3 additions & 2 deletions flask_restx/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import re

from inspect import isclass, getdoc
from collections import OrderedDict
try:
from collections.abc import OrderedDict, Hashable
from collections.abc import Hashable
except ImportError:
# TODO Remove this to drop Python2 support
from collections import OrderedDict, Hashable
from collections import Hashable
from six import string_types, itervalues, iteritems, iterkeys

from flask import current_app
Expand Down

0 comments on commit 7853511

Please sign in to comment.