mypy
mypy Error Codes
Named error codes used by mypy, the static type checker for Python. Each diagnostic carries a code that can be used to selectively ignore or enable specific checks via inline comments or configuration.
24 codes
· All codes 24 codes
- abstract Abstract Method Not Implemented A concrete subclass does not implement one or more abstract methods declared by its base class, or an abstract class is being instantiated directly.
- arg-type Incompatible Argument Type An argument passed to a function has a type that is incompatible with the corresponding parameter's declared type.
- assignment Incompatible Assignment A value of an incompatible type is assigned to a variable. The assigned value's type is not compatible with the variable's declared or inferred type.
- attr-defined Attribute Not Defined An attribute is accessed on a type that does not define it. Check for typos in the attribute name or that the object type is what you expect.
- call-overload No Matching Overload None of the overloaded variants of a function match the provided argument types. Check that the arguments match one of the declared @overload signatures.
- comparison-overlap Comparison Always True or False A comparison between two types that can never overlap (e.g. comparing an int to a str with ==) will always produce the same boolean result, suggesting a logic error.
- has-type Expression Already Has Explicit Type An expression is annotated with a type in a context where it already has an explicit type annotation, leading to a redundant or conflicting annotation.
- import-not-found Module Not Found mypy cannot locate the imported module. The module may not be installed, the path may be wrong, or a stub package may be missing.
- import-untyped Import of Untyped Module A module is imported that has no type information (neither inline annotations nor a stub package). Install the corresponding types-* stub package or add py.typed to suppress this error.
- index Unsupported Indexing Operation An indexing operation (e.g. obj[key]) is performed on a type that does not support it, or with a key of an incompatible type.
- misc Miscellaneous Error A mypy error that does not fit into any other named error code category. Used as a catch-all for checks that lack a more specific code.
- name-defined Name Not Defined A name is used that has not been defined in any accessible scope. This is often a typo, a missing import, or use of a name before it is defined.
- no-untyped-call Call to Untyped Function A typed function calls a function that has no type annotations, which means mypy cannot check the call. Enabled when --disallow-untyped-calls is set.
- no-untyped-def Function Missing Type Annotations A function or method does not have type annotations for one or more parameters or its return value. Enabled when --disallow-untyped-defs is set.
- operator Unsupported Operand Types An operator is applied to one or more operands of incompatible types (e.g. adding a string to an integer).
- override Incompatible Method Override A method in a subclass has a signature that is incompatible with the method it overrides in the base class. The overriding method must accept a superset of the base method's arguments and return a subtype of its return type.
- return Missing Return Statement A function with a non-None return type has a code path that does not return a value. Add a return statement or raise an exception on all paths.
- return-value Incompatible Return Value The type of an expression in a return statement is incompatible with the function's declared return type.
- type-arg Missing Type Argument A generic type is used without specifying its type arguments (e.g. using List instead of List[int]). Enable this check with --disallow-any-generics.
- type-var Invalid TypeVar Usage A TypeVar is used in an invalid position or without satisfying the constraints required for its declaration.
- union-attr Attribute Not Defined in Union Member An attribute is accessed on a union type but one or more union members do not define it. Narrow the type with isinstance() or other type guards before accessing the attribute.
- unreachable Unreachable Code mypy has determined that a statement or expression can never be executed based on type narrowing. This often indicates a logical error or an overly broad type guard.
- valid-type Invalid Type Expression An expression used as a type annotation is not a valid type. This can occur when using a value rather than a type, or an expression that mypy cannot interpret as a type.
- var-annotated Variable Needs Type Annotation mypy cannot infer the type of a variable from its context and requires an explicit annotation. Add a type annotation such as x: list[int] = [].