Skip to content

Commit 0c2ec6a

Browse files
authored
Document error codes (#7451)
There's a general page about what error pages and for, and I document each error code that is supported, often with code examples.
1 parent 85b04c1 commit 0c2ec6a

8 files changed

+878
-3
lines changed

docs/source/command_line.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,20 @@ in error messages.
497497
main.py:3: error: Unsupported operand types for + ("int" and "str")
498498

499499
``--show-column-numbers``
500-
This flag will add column offsets to error messages,
501-
for example, the following indicates an error in line 12, column 9
500+
This flag will add column offsets to error messages.
501+
For example, the following indicates an error in line 12, column 9
502502
(note that column offsets are 0-based)::
503503

504504
main.py:12:9: error: Unsupported operand types for / ("int" and "str")
505505

506+
``--show-error-codes``
507+
This flag will add an error code ``[<code>]`` to error messages. The error
508+
code is shown after each error message::
509+
510+
prog.py:1: error: "str" has no attribute "trim" [attr-defined]
511+
512+
See :ref:`error-codes` for more information.
513+
506514
``--no-color-output``
507515
This flag will disable color output in error messages, enabled by default.
508516

docs/source/common_issues.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ error:
124124
The second line is now fine, since the ignore comment causes the name
125125
``frobnicate`` to get an implicit ``Any`` type.
126126

127+
.. note::
128+
129+
You can use the form ``# type: ignore[<code>]`` to only ignore
130+
specific errors on the line. This way you are less likely to
131+
silence unexpected errors that are not safe to ignore, and this
132+
will also document what the purpose of the comment is. See
133+
:ref:`error-codes` for more information.
134+
127135
.. note::
128136

129137
The ``# type: ignore`` comment will only assign the implicit ``Any``

docs/source/config_file.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,16 @@ section of the command line docs.
441441
``show_column_numbers`` (bool, default False)
442442
Shows column numbers in error messages.
443443

444+
``show_error_codes`` (bool, default False)
445+
Shows error codes in error messages. See :ref:`error-codes` for more information.
446+
444447
``color_output`` (bool, default True)
445448
Shows error messages with color enabled.
446449

447450
``error_summary`` (bool, default True)
448451
Shows a short summary line after error messages.
449452

453+
450454
Advanced options
451455
----------------
452456

0 commit comments

Comments
 (0)