Import Mapping and Sequence from compat in python_api::approx

Related to https://github.com/pytest-dev/pytest/issues/3339

Fixes a DeprecationWarning on Python 3.7

Adds Mapping to compat
This commit is contained in:
Miro Hrončok 2018-05-22 21:58:31 +02:00
parent 6c8d46d8ea
commit 5072226f69
4 changed files with 9 additions and 3 deletions

View File

@ -144,6 +144,7 @@ Michael Seifert
Michal Wajszczuk Michal Wajszczuk
Mihai Capotă Mihai Capotă
Mike Lundy Mike Lundy
Miro Hrončok
Nathaniel Waisbrot Nathaniel Waisbrot
Ned Batchelder Ned Batchelder
Neven Mundar Neven Mundar

View File

@ -40,11 +40,11 @@ MODULE_NOT_FOUND_ERROR = 'ModuleNotFoundError' if PY36 else 'ImportError'
if _PY3: if _PY3:
from collections.abc import MutableMapping as MappingMixin # noqa from collections.abc import MutableMapping as MappingMixin # noqa
from collections.abc import Sequence # noqa from collections.abc import Mapping, Sequence # noqa
else: else:
# those raise DeprecationWarnings in Python >=3.7 # those raise DeprecationWarnings in Python >=3.7
from collections import MutableMapping as MappingMixin # noqa from collections import MutableMapping as MappingMixin # noqa
from collections import Sequence # noqa from collections import Mapping, Sequence # noqa
def _format_args(func): def _format_args(func):

View File

@ -426,7 +426,7 @@ def approx(expected, rel=None, abs=None, nan_ok=False):
__ https://docs.python.org/3/reference/datamodel.html#object.__ge__ __ https://docs.python.org/3/reference/datamodel.html#object.__ge__
""" """
from collections import Mapping, Sequence from _pytest.compat import Mapping, Sequence
from _pytest.compat import STRING_TYPES as String from _pytest.compat import STRING_TYPES as String
from decimal import Decimal from decimal import Decimal

View File

@ -0,0 +1,5 @@
Import ``Mapping`` and ``Sequence`` from ``_pytest.compat`` instead of directly
from ``collections`` in ``python_api.py::approx``. Add ``Mapping`` to
``_pytest.compat``, import it from ``collections`` on python 2, but from
``collections.abc`` on Python 3 to avoid a ``DeprecationWarning`` on
Python 3.7 or newer.