Skip to content

Commit ac1fb07

Browse files
authored
bpo-47235: Note where a typo is intentional in code. (GH-32348)
People keep popping up reporting these as typos in the docs despite being described as typos in the surrounding text. Hopefully a comment on the line itself makes it more obvious? Arguably some of the typo examples are not using the "right" typo as the "assret" one in particular is now detected by default due to how common it was in actual code. But I don't want to to typo chasing by changing these examples to be other not yet auto-detected typos as they still illustrate the point well enough.
1 parent d79f118 commit ac1fb07

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Doc/library/unittest.mock.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,7 +2550,7 @@ your assertion is gone:
25502550
25512551
>>> mock = Mock(name='Thing', return_value=None)
25522552
>>> mock(1, 2, 3)
2553-
>>> mock.assret_called_once_with(4, 5, 6)
2553+
>>> mock.assret_called_once_with(4, 5, 6) # Intentional typo!
25542554
25552555
Your tests can pass silently and incorrectly because of the typo.
25562556

@@ -2570,7 +2570,7 @@ attributes on the mock that exist on the real class:
25702570

25712571
>>> from urllib import request
25722572
>>> mock = Mock(spec=request.Request)
2573-
>>> mock.assret_called_with
2573+
>>> mock.assret_called_with # Intentional typo!
25742574
Traceback (most recent call last):
25752575
...
25762576
AttributeError: Mock object has no attribute 'assret_called_with'
@@ -2582,7 +2582,7 @@ with any methods on the mock:
25822582
25832583
>>> mock.has_data()
25842584
<mock.Mock object at 0x...>
2585-
>>> mock.has_data.assret_called_with()
2585+
>>> mock.has_data.assret_called_with() # Intentional typo!
25862586
25872587
Auto-speccing solves this problem. You can either pass ``autospec=True`` to
25882588
:func:`patch` / :func:`patch.object` or use the :func:`create_autospec` function to create a
@@ -2625,7 +2625,7 @@ any typos in our asserts will raise the correct error::
26252625

26262626
>>> req.add_header('spam', 'eggs')
26272627
<MagicMock name='request.Request().add_header()' id='...'>
2628-
>>> req.add_header.assret_called_with
2628+
>>> req.add_header.assret_called_with # Intentional typo!
26292629
Traceback (most recent call last):
26302630
...
26312631
AttributeError: Mock object has no attribute 'assret_called_with'

0 commit comments

Comments
 (0)