From 4f11440c7c5b12f33cf934fdb8bf8e46719fa072 Mon Sep 17 00:00:00 2001 From: Callum Scott <134177091+callummscott@users.noreply.github.com> Date: Thu, 3 Apr 2025 13:53:43 +0100 Subject: [PATCH] Add title and change spelling for use of approx with non-numerics (#13343) * Added title to draw attention to the easily-missed information on non-numeric types for approx. * Changed spelling of all cases of "nonnumeric" to "non-numeric" within docstrings for clarity and consistency with .rst files. Related to #13218 (cherry picked from commit 9a7dbd8a394bb47ee43be51d60ec3c4f4759789e) --- src/_pytest/python_api.py | 10 ++++++---- testing/python/approx.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index 8f73f68d0d5..4e8271507fb 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -637,8 +637,10 @@ def approx(expected, rel=None, abs=None, nan_ok: bool = False) -> ApproxBase: >>> 1 + 1e-8 == approx(1, rel=1e-6, abs=1e-12) True - You can also use ``approx`` to compare nonnumeric types, or dicts and - sequences containing nonnumeric types, in which case it falls back to + **Non-numeric types** + + You can also use ``approx`` to compare non-numeric types, or dicts and + sequences containing non-numeric types, in which case it falls back to strict equality. This can be useful for comparing dicts and sequences that can contain optional values:: @@ -713,10 +715,10 @@ def approx(expected, rel=None, abs=None, nan_ok: bool = False) -> ApproxBase: .. versionchanged:: 3.7.1 ``approx`` raises ``TypeError`` when it encounters a dict value or - sequence element of nonnumeric type. + sequence element of non-numeric type. .. versionchanged:: 6.1.0 - ``approx`` falls back to strict equality for nonnumeric types instead + ``approx`` falls back to strict equality for non-numeric types instead of raising ``TypeError``. """ # Delegate the comparison to a class that knows how to deal with the type diff --git a/testing/python/approx.py b/testing/python/approx.py index 5b80d0d640d..23ae4b115a6 100644 --- a/testing/python/approx.py +++ b/testing/python/approx.py @@ -902,7 +902,7 @@ def test_nonnumeric_okay_if_equal(self, x): ], ) def test_nonnumeric_false_if_unequal(self, x): - """For nonnumeric types, x != pytest.approx(y) reduces to x != y""" + """For non-numeric types, x != pytest.approx(y) reduces to x != y""" assert "ab" != approx("abc") assert ["ab"] != approx(["abc"]) # in particular, both of these should return False