Skip to content

Commit

Permalink
Merge pull request #732 from Colin-b/bugfix/python_38_support
Browse files Browse the repository at this point in the history
Import the ABCs from 'collections.abc' instead of 'collections'
  • Loading branch information
ziirish committed Oct 22, 2019
2 parents c92a126 + 136da9d commit c25dc45
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Current
-------

- Ensure that exceptions raised in error handler, including programming errors, are logged (:issue:`705`, :pr:`706`)
- Import the ABCs from 'collections.abc' instead of 'collections' by default as it is deprecated since Python3.7, and in 3.8 it will stop working. Python2.7 is still supported though.

0.13.0 (2019-08-12)
-------------------
Expand Down
6 changes: 1 addition & 5 deletions doc/marshalling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,11 @@ with other fields, you may want to use an ``OrderedDict`` and use the
:class:`~fields.Wildcard` as the last field ::

>>> from flask_restplus import fields, marshal
>>> from collections import OrderedDict
>>> import json
>>>
>>> wild = fields.Wildcard(fields.Integer)
>>> mod = OrderedDict()
>>> mod['zoro'] = fields.String
>>> mod['*'] = wild
>>> # you can use it in api.model like this:
>>> # some_fields = api.model('MyModel', mod)
>>> # some_fields = api.model('MyModel', {'zoro': fields.String, '*': wild})
>>>
>>> data = {'John': 12, 'bob': 42, 'Jane': '68', 'zoro': 72}
>>> json.dumps(marshal(data, mod))
Expand Down
2 changes: 0 additions & 2 deletions doc/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ you use the ``fields`` module to describe the structure of your response.

.. code-block:: python
from collections import OrderedDict
from flask import Flask
from flask_restplus import fields, Api, Resource
Expand Down
6 changes: 5 additions & 1 deletion flask_restplus/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import six
import sys

from collections import OrderedDict
try:
from collections.abc import OrderedDict
except ImportError:
# TODO Remove this to drop Python2 support
from collections import OrderedDict
from functools import wraps, partial
from types import MethodType

Expand Down
6 changes: 5 additions & 1 deletion flask_restplus/marshalling.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from collections import OrderedDict
try:
from collections.abc import OrderedDict
except ImportError:
# TODO Remove this to drop Python2 support
from collections import OrderedDict
from functools import wraps
from six import iteritems

Expand Down
6 changes: 5 additions & 1 deletion flask_restplus/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import re
import six

from collections import OrderedDict
try:
from collections.abc import OrderedDict
except ImportError:
# TODO Remove this to drop Python2 support
from collections import OrderedDict
from inspect import isclass

from .errors import RestError
Expand Down
6 changes: 5 additions & 1 deletion flask_restplus/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import re
import warnings

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

Expand Down
7 changes: 5 additions & 2 deletions flask_restplus/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
import json
import pkg_resources

from collections import Mapping

try:
from collections.abc import Mapping
except ImportError:
# TODO Remove this to drop Python2 support
from collections import Mapping
from jsonschema import Draft4Validator

from flask_restplus import errors
Expand Down
6 changes: 3 additions & 3 deletions flask_restplus/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import re

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

from flask import current_app
Expand Down
6 changes: 5 additions & 1 deletion flask_restplus/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

import re

from collections import OrderedDict
try:
from collections.abc import OrderedDict
except ImportError:
# TODO Remove this to drop Python2 support
from collections import OrderedDict
from copy import deepcopy
from six import iteritems

Expand Down
6 changes: 5 additions & 1 deletion tests/test_fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from collections import OrderedDict
try:
from collections.abc import OrderedDict
except ImportError:
# TODO Remove this to drop Python2 support
from collections import OrderedDict
from datetime import date, datetime
from decimal import Decimal
from functools import partial
Expand Down
6 changes: 5 additions & 1 deletion tests/test_fields_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import json
import pytest

from collections import OrderedDict
try:
from collections.abc import OrderedDict
except ImportError:
# TODO Remove this to drop Python2 support
from collections import OrderedDict

from flask_restplus import mask, Api, Resource, fields, marshal, Mask

Expand Down
6 changes: 5 additions & 1 deletion tests/test_marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
marshal, marshal_with, marshal_with_field, fields, Api, Resource
)

from collections import OrderedDict
try:
from collections.abc import OrderedDict
except ImportError:
# TODO Remove this to drop Python2 support
from collections import OrderedDict


# Add a dummy Resource to verify that the app is properly set.
Expand Down
6 changes: 5 additions & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import copy
import pytest

from collections import OrderedDict
try:
from collections.abc import OrderedDict
except ImportError:
# TODO Remove this to drop Python2 support
from collections import OrderedDict

from flask_restplus import fields, Model, OrderedModel, SchemaModel

Expand Down

0 comments on commit c25dc45

Please sign in to comment.