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:
  1. class Test:
  2. def foo(self, x: int) -> int:
  3. return x + "bar"

Mypy normally displays an error message that looks like this:

  1. main.py:3: error: Unsupported operand types for + ("int" and "str")

If we enable this flag, the error message now looks like this:

  1. main.py: note: In member "foo" of class "Test":
  2. 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):
  1. 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:
  1. 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.
  • —no-color-output
  • This flag will disable color output in error messages, enabled by default.
  • —no-error-summary
  • This flag will disable error summary. By default mypy shows a summary lineincluding total number of errors, number of files with errors, and numberof files checked.
  • —show-absolute-path
  • Show absolute paths to files.