Skip to content

Commit

Permalink
Import Mapping and Sequence from compat in python_api::approx
Browse files Browse the repository at this point in the history
Related to pytest-dev#3339

Fixes a DeprecationWarning on Python 3.7

Adds Mapping to compat
  • Loading branch information
hroncok committed May 22, 2018
1 parent 6c8d46d commit 5072226
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Michael Seifert
Michal Wajszczuk
Mihai Capotă
Mike Lundy
Miro Hrončok
Nathaniel Waisbrot
Ned Batchelder
Neven Mundar
Expand Down
4 changes: 2 additions & 2 deletions _pytest/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@

if _PY3:
from collections.abc import MutableMapping as MappingMixin # noqa
from collections.abc import Sequence # noqa
from collections.abc import Mapping, Sequence # noqa
else:
# those raise DeprecationWarnings in Python >=3.7
from collections import MutableMapping as MappingMixin # noqa
from collections import Sequence # noqa
from collections import Mapping, Sequence # noqa


def _format_args(func):
Expand Down
2 changes: 1 addition & 1 deletion _pytest/python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def approx(expected, rel=None, abs=None, nan_ok=False):
__ 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 decimal import Decimal

Expand Down
5 changes: 5 additions & 0 deletions changelog/3497.trivial.rst
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 5072226

Please sign in to comment.