Skip to content

Commit 9a7dbd8

Browse files
authored
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
1 parent 682013d commit 9a7dbd8

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/_pytest/python_api.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,10 @@ def approx(expected, rel=None, abs=None, nan_ok: bool = False) -> ApproxBase:
632632
>>> 1 + 1e-8 == approx(1, rel=1e-6, abs=1e-12)
633633
True
634634
635-
You can also use ``approx`` to compare nonnumeric types, or dicts and
636-
sequences containing nonnumeric types, in which case it falls back to
635+
**Non-numeric types**
636+
637+
You can also use ``approx`` to compare non-numeric types, or dicts and
638+
sequences containing non-numeric types, in which case it falls back to
637639
strict equality. This can be useful for comparing dicts and sequences that
638640
can contain optional values::
639641
@@ -708,10 +710,10 @@ def approx(expected, rel=None, abs=None, nan_ok: bool = False) -> ApproxBase:
708710
709711
.. versionchanged:: 3.7.1
710712
``approx`` raises ``TypeError`` when it encounters a dict value or
711-
sequence element of nonnumeric type.
713+
sequence element of non-numeric type.
712714
713715
.. versionchanged:: 6.1.0
714-
``approx`` falls back to strict equality for nonnumeric types instead
716+
``approx`` falls back to strict equality for non-numeric types instead
715717
of raising ``TypeError``.
716718
"""
717719
# Delegate the comparison to a class that knows how to deal with the type

testing/python/approx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ def test_nonnumeric_okay_if_equal(self, x):
939939
],
940940
)
941941
def test_nonnumeric_false_if_unequal(self, x):
942-
"""For nonnumeric types, x != pytest.approx(y) reduces to x != y"""
942+
"""For non-numeric types, x != pytest.approx(y) reduces to x != y"""
943943
assert "ab" != approx("abc")
944944
assert ["ab"] != approx(["abc"])
945945
# in particular, both of these should return False

0 commit comments

Comments
 (0)