Only function declarations are considered by this plugin; type annotations in function/module bodies are not checked
Common pitfall: the use of ignore will enable all implicitly disabled warnings
Configuration Options
Some opinionated flags are provided to tailor the linting errors emitted.
--suppress-none-returning: bool
Suppress ANN200-level errors for functions that meet one of the following criteria:
Contain no return statement, or
Explicit return statement(s) all return None (explicitly or implicitly).
Default: False
--suppress-dummy-args: bool
Suppress ANN000-level errors for dummy arguments, defined as _.
Default: False
--allow-untyped-defs: bool
Suppress all errors for dynamically typed functions. A function is considered dynamically typed if it does not contain any type hints.
Default: False
--allow-untyped-nested: bool
Suppress all errors for dynamically typed nested functions. A function is considered dynamically typed if it does not contain any type hints.
Default: False
--mypy-init-return: bool
Allow omission of a return type hint for __init__ if at least one argument is annotated. See mypy's documentation for additional details.
Default: False
--dispatch-decorators: list[str]
Comma-separated list of decorators flake8-annotations should consider as dispatch decorators. Linting errors are suppressed for functions decorated with at least one of these functions.
Decorators are matched based on their attribute name. For example, "singledispatch" will match any of the following:
import functools; @functools.singledispatch
import functools as <alias>; @<alias>.singledispatch
from functools import singledispatch; @singledispatch
NOTE: Deeper imports, such as a.b.singledispatch are not supported.
Suppress ANN401 for dynamically typed *args and **kwargs.
Default: False
--respect-type-ignore
Suppress linting errors for functions annotated with a # type: ignore comment. Support is also provided for module-level blanket ignores (see: mypy: Ignoring a whole file).
NOTE: Type ignore tags are not considered, e.g. # type: ignore[arg-type] is treated the same as # type: ignore.
NOTE: Module-level suppression is only considered for the # mypy: ignore-errors or # type: ignore tags when provided as the sole contents of the first line of the module.
A function composed of multiple functions implementing the same operation for different types. Which implementation should be used during a call is determined by the dispatch algorithm.
In the standard library we have some examples of decorators for implementing these generic functions: functools.singledispatch and functools.singledispatchmethod. In the spirit of the purpose of these decorators, errors for missing annotations for functions decorated with at least one of these are ignored.
For example, this code:
import functools
@functools.singledispatch
def foo(a):
print(a)
@foo.register
def _(a: list) -> None:
for idx, thing in enumerate(a):
print(idx, thing)
Will not raise any linting errors for foo.
Decorator(s) to treat as defining generic functions may be specified by the --dispatch-decorators configuration option.
The @overload decorator allows describing functions and methods that support multiple different combinations of argument types. A series of @overload-decorated definitions must be followed by exactly one non-@overload-decorated definition (for the same function/method).
In the spirit of the purpose of this decorator, errors for missing annotations for non-@overload-decorated functions are ignored if they meet these criteria.