Skip to content

Commit 7985eff

Browse files
authored
Merge pull request #3497 from hroncok/approx_compat_import
Import Mapping and Sequence from compat in python_api::approx
2 parents 6c8d46d + 5072226 commit 7985eff

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Michael Seifert
144144
Michal Wajszczuk
145145
Mihai Capotă
146146
Mike Lundy
147+
Miro Hrončok
147148
Nathaniel Waisbrot
148149
Ned Batchelder
149150
Neven Mundar

_pytest/compat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040

4141
if _PY3:
4242
from collections.abc import MutableMapping as MappingMixin # noqa
43-
from collections.abc import Sequence # noqa
43+
from collections.abc import Mapping, Sequence # noqa
4444
else:
4545
# those raise DeprecationWarnings in Python >=3.7
4646
from collections import MutableMapping as MappingMixin # noqa
47-
from collections import Sequence # noqa
47+
from collections import Mapping, Sequence # noqa
4848

4949

5050
def _format_args(func):

_pytest/python_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def approx(expected, rel=None, abs=None, nan_ok=False):
426426
__ https://docs.python.org/3/reference/datamodel.html#object.__ge__
427427
"""
428428

429-
from collections import Mapping, Sequence
429+
from _pytest.compat import Mapping, Sequence
430430
from _pytest.compat import STRING_TYPES as String
431431
from decimal import Decimal
432432

changelog/3497.trivial.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Import ``Mapping`` and ``Sequence`` from ``_pytest.compat`` instead of directly
2+
from ``collections`` in ``python_api.py::approx``. Add ``Mapping`` to
3+
``_pytest.compat``, import it from ``collections`` on python 2, but from
4+
``collections.abc`` on Python 3 to avoid a ``DeprecationWarning`` on
5+
Python 3.7 or newer.

0 commit comments

Comments
 (0)