Skip to content

Commit f76889a

Browse files
authored
Fix doctest doc examples for syntax errors (GH-28486)
* fix doctest doc examples for syntax errors * updated examples to use TypeErrors * fixed first sentence * unneeded comma
1 parent bc4cde4 commit f76889a

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

Doc/library/doctest.rst

+10-11
Original file line numberDiff line numberDiff line change
@@ -485,25 +485,24 @@ Some details you should read once, but won't need to remember:
485485

486486
.. index:: single: ^ (caret); marker
487487

488-
* For some :exc:`SyntaxError`\ s, Python displays the character position of the
489-
syntax error, using a ``^`` marker::
488+
* For some exceptions, Python displays the position of the error using ``^``
489+
markers and tildes::
490490

491-
>>> 1 1
491+
>>> 1 + None
492492
File "<stdin>", line 1
493-
1 1
494-
^
495-
SyntaxError: invalid syntax
493+
1 + None
494+
~~^~~~~~
495+
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
496496

497497
Since the lines showing the position of the error come before the exception type
498498
and detail, they are not checked by doctest. For example, the following test
499499
would pass, even though it puts the ``^`` marker in the wrong location::
500500

501-
>>> 1 1
502-
Traceback (most recent call last):
501+
>>> 1 + None
503502
File "<stdin>", line 1
504-
1 1
505-
^
506-
SyntaxError: invalid syntax
503+
1 + None
504+
^~~~~~~~
505+
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
507506

508507

509508
.. _option-flags-and-directives:

0 commit comments

Comments
 (0)