# type: ignore comments.
Error code structure
ErrorCode class
Each error code in Mypy is represented by anErrorCode instance defined in mypy.errorcodes.
The error code identifier (e.g.,
"attr-defined", "type-arg")Human-readable description of what this error checks
Category of the error (currently always
"General")Whether this error code is enabled by default
Parent error code if this is a more specific variant
Error code categories
Mypy’s error codes fall into several categories:Type errors
Errors related to type incompatibilities and type checking:attr-defined- Attribute existence checksarg-type- Argument type mismatchesreturn-value- Return type mismatchesassignment- Assignment type mismatchesoverride- Method override compatibility
Syntax errors
Errors related to Python syntax:syntax- Syntax errors in Python code
Other errors
Import errors, definition errors, and other checks:import-not-found- Missing importsname-defined- Undefined namesno-redef- Duplicate definitions
Using error codes
In type: ignore comments
Specify which errors to ignore:Enable/disable error codes
Use command-line flags or config file:mypy.ini:
Per-module configuration
Error code hierarchy
Some error codes have sub-codes for more specific cases:Default vs optional error codes
Enabled by default
Most error codes are enabled by default:Disabled by default
Some stricter checks require opt-in:Accessing error codes programmatically
Get all error codes
Check if a code is enabled
Sub-code mapping
Common error codes
Here are the most frequently encountered error codes:attr-defined
Check that attributes exist on objects
name-defined
Check that names are defined before use
arg-type
Check argument types in function calls
return-value
Check return value matches function signature
assignment
Check assignment type compatibility
import-not-found
Check that imports can be resolved
Error code reference
All error codes list
Mypy defines over 60 error codes. They are documented in detail across these pages:Type errors
Type checking error codes
Syntax errors
Syntax and parsing errors
Other errors
Import, definition, and other errors
Special error codes
misc
The catch-all error code for various uncategorized checks:syntax
Syntax errors are often blocking (cannot be ignored):Best practices
Use specific error codes
Enable strict optional checks
Document ignored errors
See also
- Type error codes - Type checking errors
- Syntax error codes - Syntax errors
- Other error codes - Import and definition errors
- Configuration - How to configure error codes