Silencing errors based on error codes

You can use a special comment # type: ignore[code, …] to onlyignore errors with a specific error code (or codes) on a particularline. This can be used even if you have not configured mypy to showerror codes. Currently it’s only possible to disable arbitrary errorcodes on individual lines using this comment.

Note

There are command-line flags and config file settings for enablingcertain optional error codes, such as —disallow-untyped-defs,which enables the no-untyped-def error code.

This example shows how to ignore an error about an imported name mypythinks is undefined:

  1. # 'foo' is defined in 'foolib', even though mypy can't see the
  2. # definition.
  3. from foolib import foo # type: ignore[attr-defined]