Rules
invalid-function-defaults
What it does
Checks for invalid mutations of the __defaults__ attribute of a function.
Why is this bad?
Modifying the __defaults__ attribute with types different to the parameters
can lead to runtime type errors.
Examples
| Python | |
|---|---|
1 2 3 4 5 | |
Default level: error.
Categories: runtime-modification.
invalid-overload-implementation
What it does
Checks for invalid overload implementation.
Why is this bad?
Invalid overload implementation can lead to runtime errors.
Examples
| Python | |
|---|---|
1 2 3 4 5 6 7 8 9 10 | |
Default level: error.
Categories: type-checking-suppression.
invalid-setattr
What it does
Checks for invalid setattr() usage.
Why is this bad?
setattr() bypasses type checking by allowing "dynamic" attribute assignment.
You can assign any type to any attribute, which can lead to runtime type errors
when the actual type doesn't match the declared type annotation.
Examples
| Python | |
|---|---|
1 2 3 4 5 6 | |
Default level: error.
Categories: runtime-modification.
mutable-generic-default
What it does
Checks for generic functions or methods that accept mutable objects as default parameter values.
Why is this bad?
When a generic function uses a mutable default value (like a list, dict, or set), that default is shared across all invocations of the function. This creates a scenario where the mutable object can accumulate values of different types from different calls.
Type checkers assume that list[T] only contains values of type T. However, when a mutable
default is reused across calls with different type parameters, the list can contain values of
multiple different types, leading to runtime type errors.
Examples
| Python | |
|---|---|
1 2 3 4 5 6 7 8 9 | |
Default level: error.
Categories: runtime-modification.
mutating-function-code-attribute
What it does
Checks for mutating the __code__ attribute of a function.
Why is this bad?
Modifying the __code__ attribute allows runtime modification
of function internals, which can bypass type checking and lead to runtime type errors.
Type checkers cannot analyze or verify operations performed through code objects.
Examples
| Python | |
|---|---|
1 2 3 4 5 6 7 8 | |
Default level: error.
Categories: runtime-modification.
mutating-globals-dict
What it does
Checks for mutations to the globals() dictionary.
Why is this bad?
Modifying the globals() dictionary allows runtime modification
of global variables, which can bypass type checking and lead to runtime type errors.
Type checkers cannot track or verify modifications made through the globals dictionary.
Examples
| Python | |
|---|---|
1 2 3 4 5 6 | |
Default level: error.
Categories: runtime-modification.
callable-ellipsis-used
What it does
Checks for usage of ... (ellipsis) in the first argument of Callable type annotations.
Why is this bad?
Using Callable[..., ReturnType] indicates that the callable accepts any number
of arguments of any type, which bypasses parameter type checking. This can lead to
runtime type errors as the type checker cannot verify argument types or counts.
Examples
| Python | |
|---|---|
1 2 3 4 5 6 7 8 9 10 | |
Default level: warn.
Categories: type-checking-suppression.
if-type-checking-used
What it does
Checks for usage of if TYPE_CHECKING: blocks from the typing module.
Why is this bad?
TYPE_CHECKING is False at runtime but True during static type checking.
When used with an else clause where signatures don't match, the type checker
validates against the if TYPE_CHECKING branch, but at runtime the else branch
executes, causing runtime type errors that the type checker can't catch.
Examples
| Python | |
|---|---|
1 2 3 4 5 6 7 8 9 10 | |
Default level: warn.
Categories: type-checking-suppression.
mangled-dunder-instance-variable
What it does
Checks for explicit usage of mangled dunder instance variables in attribute access.
Why is this bad?
Python automatically mangles double-underscore (dunder) instance variables to
_ClassName__variable to provide name privacy. When code explicitly uses the
mangled form, it can bypass type checking by assigning different types to the
mangled name than what the non-mangled variable expects.
Examples
| Python | |
|---|---|
1 2 3 4 5 6 7 8 9 10 | |
Default level: warn.
Categories: type-checking-suppression.
type-checking-directive-used
What it does
Checks for usage of type checking directives in comments.
Why is this bad?
Type checking directives like # type: ignore suppress type checker warnings,
which can hide potential type errors that may lead to runtime failures.
These directives bypass the safety guarantees that type checking provides.
Examples
| Python | |
|---|---|
1 2 3 | |
Default level: warn.
Categories: type-checking-suppression.
typing-any-used
What it does
Checks for usage of typing.Any in type annotations.
Why is this bad?
Using typing.Any in type annotations can lead to runtime errors.
Examples
| Python | |
|---|---|
1 2 3 4 5 6 | |
Default level: warn.
Categories: type-checking-suppression.
typing-cast-used
What it does
Checks for usage of typing.cast() function calls.
Why is this bad?
typing.cast() tells the type checker to treat a value as a specific type
without any runtime checks or validation. This can lead to runtime type errors
if the cast is incorrect. Type checkers trust casts completely, so incorrect
casts bypass all type safety guarantees.
Examples
| Python | |
|---|---|
1 2 3 4 5 6 7 | |
Default level: warn.
Categories: type-checking-suppression.
typing-overload-used
What it does
Checks for usage of overloaded functions.
Why is this bad?
Using overloaded functions can lead to runtime errors. When users don't follow the correct overload implementation, it can lead to unexpected behavior.
Examples
| Python | |
|---|---|
1 2 3 4 5 6 7 8 | |
Default level: warn.
Categories: type-checking-suppression.
typing-type-is-used
What it does
Checks for return types that use typing.TypeIs.
Why is this bad?
Using typing.TypeIs in return type annotations can lead to runtime type errors.
Type checkers use TypeIs to narrow types, but incorrect implementation can bypass
type safety guarantees.
Examples
| Python | |
|---|---|
1 2 3 4 5 6 7 8 9 | |
Default level: warn.
Categories: type-checking-suppression.