Configuring error messages
The following flags let you adjust how much detail mypy displaysin error messages.
—show-error-context
- This flag will precede all errors with “note” messages explaining thecontext of the error. For example, consider the following program:
- class Test:
- def foo(self, x: int) -> int:
- return x + "bar"
Mypy normally displays an error message that looks like this:
- main.py:3: error: Unsupported operand types for + ("int" and "str")
If we enable this flag, the error message now looks like this:
- main.py: note: In member "foo" of class "Test":
- main.py:3: error: Unsupported operand types for + ("int" and "str")
—show-column-numbers
- This flag will add column offsets to error messages.For example, the following indicates an error in line 12, column 9(note that column offsets are 0-based):
- main.py:12:9: error: Unsupported operand types for / ("int" and "str")
—show-error-codes
- This flag will add an error code
[<code>]
to error messages. The errorcode is shown after each error message:
- prog.py:1: error: "str" has no attribute "trim" [attr-defined]
See Error codes for more information.
—pretty
- Use visually nicer output in error messages: use soft word wrap,show source code snippets, and show error location markers.