Flake8 Type Annotation Checking
ANN402
for the presence of type commentsANN301
attrs
.flake8 >= 5.0
(See: https://github.com/pycqa/flake8/issues/284)--dispatch-decorators
to support suppression of all errors from functions decorated by decorators such as functools.singledispatch
and functools.singledispatchmethod
.--overload-decorators
to support generic aliasing of the typing.overload
decorator.Per #98, the functools.singledispatch
and functools.singledispatchmethod
decorators transform a function into a single-dispatch generic function.
For example:
import functools
@functools.singledispatch
def foo(a):
print(a)
@foo.register
def _(a: list) -> None:
for idx, thing in enumerate(a):
print(idx, thing)
Is correctly annotated but would previously yield linting errors for foo
. In the spirit of the purpose of these decorators, linting errors are now suppressed for functions decorated with these decorators. The --dispatch-decorators
configuration option has been added, which specifies a comma-separated list of decorators to be considered as dispatch decorators.
Decorators are matched based on their attribute name. For example, "singledispatch"
will match any of the following:
import functools; @functools.singledispatch
import functools as fnctls; @fnctls.singledispatch
from functools import singledispatch; @singledispatch
By default, linting errors are suppressed for functions decorated by singledispatch
or singledispatchmethod
.
typing.overload
decorator aliasingPer #99, handling of the typing.overload
has been made generic, removing the caveat from the initial implementation. The --overload-decorators
configuration option has been added, which specifies a comma-separated list of decorators to be considered as typing.overload
decorators.
Decorators are now matched based on their attribute name. For example, "overload"
will match any of the following:
import typing; @typing.overload
import typing as t; @t.overload
from typing import overload; @overload
By default, linting errors are suppressed for functions decorated by overload
, which should be a transparent change from v2.4 (#97).
--allow-untyped-nested
to suppress all errors from dynamically typted nested functions. A function is considered dynamically typed if it does not contain any type hints.Per #102, nested functions can fall into an interesting spot semantically for a project. They're distinct enough from private/secret functions that one may not want to strictly enforce annotation (e.g. decorator definitions) but there does not exist a mechanism to do so without either noqa
or just allowing all dynamically typed functions (via --allow-untyped-defs
). The --allow-untyped-nested
flag allows for this stricter subset of dynamic functions.