You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*#98 Add `--dispatch-decorators` to support suppression of all errors from functions decorated by decorators such as `functools.singledispatch` and `functools.singledispatchmethod`.
7
+
*#99 Add `--overload-decorators` to support generic aliasing of the `typing.overload` decorator.
8
+
9
+
### Fixed
10
+
*#106 Fix incorrect parsing of multiline docstrings with less than two lines of content, causing incorrect line numbers for yielded errors in Python versions prior to 3.8
11
+
4
12
## [v2.5.0]
5
13
### Added
6
-
*#103add`--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.
14
+
*#103Add`--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.
`flake8-annotations` is a plugin for [Flake8](http://flake8.pycqa.org/en/latest/) that detects the absence of [PEP 3107-style](https://www.python.org/dev/peps/pep-3107/) function annotations and [PEP 484-style](https://www.python.org/dev/peps/pep-0484/#type-comments) type comments (see: [Caveats](#Caveats-for-PEP-484-style-Type-Comments)).
8
+
`flake8-annotations` is a plugin for [Flake8](http://flake8.pycqa.org/en/latest/) that detects the absence of [PEP 3107-style](https://www.python.org/dev/peps/pep-3107/) function annotations and [PEP 484-style](https://www.python.org/dev/peps/pep-0484/#type-comments) type comments (see: [Caveats](#Caveats-for-PEP-484-style-Type-Comments)).
6
9
7
10
What this won't do: Check variable annotations (see: [PEP 526](https://www.python.org/dev/peps/pep-0526/)), respect stub files, or replace [mypy](http://mypy-lang.org/).
8
11
@@ -19,7 +22,7 @@ You can verify it's being picked up by invoking the following in your shell:
19
22
20
23
```bash
21
24
$ flake8 --version
22
-
3.8.4 (flake8-annotations: 2.5.0, mccabe: 0.6.1, pycodestyle: 2.6.0, pyflakes: 2.2.0) CPython 3.9.0 on Darwin
25
+
3.8.4 (flake8-annotations: 2.6.0, mccabe: 0.6.1, pycodestyle: 2.6.0, pyflakes: 2.2.0) CPython 3.9.0 on Darwin
23
26
```
24
27
25
28
## Table of Warnings
@@ -86,6 +89,61 @@ Allow omission of a return type hint for `__init__` if at least one argument is
86
89
87
90
Default: `False`
88
91
92
+
### `--dispatch-decorators`: `list[str]`
93
+
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.
94
+
95
+
Decorators are matched based on their attribute name. For example, `"singledispatch"` will match any of the following:
96
+
*`import functools; @functools.singledispatch`
97
+
*`import functools as fnctls; @fnctls.singledispatch`
**NOTE:** Deeper imports, such as `a.b.singledispatch` are not supported.
101
+
102
+
See: [Generic Functions](#generic-functions) for additional information.
103
+
104
+
Default: `"singledispatch, singledispatchmethod"`
105
+
106
+
### `--overload-decorators`: `list[str]`
107
+
Comma-separated list of decorators flake8-annotations should consider as [`typing.overload`](https://docs.python.org/3/library/typing.html#typing.overload) decorators.
108
+
109
+
Decorators are matched based on their attribute name. For example, `"overload"` will match any of the following:
110
+
*`import typing; @typing.overload`
111
+
*`import typing as t; @t.overload`
112
+
*`from typing import overload; @overload`
113
+
114
+
**NOTE:** Deeper imports, such as `a.b.overload` are not supported.
115
+
116
+
See: [The `typing.overload` Decorator](#the-typingoverload-decorator) for additional information.
117
+
118
+
Default: `"overload"`
119
+
120
+
121
+
## Generic Functions
122
+
Per the Python Glossary, a [generic function](https://docs.python.org/3/glossary.html#term-generic-function) is defined as:
123
+
124
+
> 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.
125
+
126
+
In the standard library we have some examples of decorators for implementing these generic functions: [`functools.singledispatch`](https://docs.python.org/3/library/functools.html#functools.singledispatch) and [`functools.singledispatchmethod`](https://docs.python.org/3/library/functools.html#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.
127
+
128
+
For example, this code:
129
+
130
+
```py
131
+
import functools
132
+
133
+
@functools.singledispatch
134
+
deffoo(a):
135
+
print(a)
136
+
137
+
@foo.register
138
+
def_(a: list) -> None:
139
+
for idx, thing inenumerate(a):
140
+
print(idx, thing)
141
+
```
142
+
143
+
Will not raise any linting errors for `foo`.
144
+
145
+
Decorator(s) to treat as defining generic functions may be specified by the [`--dispatch-decorators`](#--dispatch-decorators-liststr) configuration option.
146
+
89
147
## The `typing.overload` Decorator
90
148
Per the [`typing`](https://docs.python.org/3/library/typing.html#typing.overload) documentation:
91
149
@@ -109,7 +167,7 @@ def foo(a):
109
167
110
168
Will not raise linting errors for missing annotations for the arguments & return of the non-decorated `foo` definition.
111
169
112
-
**NOTE:** If importing directly, the `typing.overload`decorator will not be recognized if it is imported with an alias (e.g. `from typing import overload as please_dont_do_this`). Aliasing of the `typing` module is supported (e.g. `import typing as t; @t.overload`).
170
+
Decorator(s) to treat as `typing.overload`may be specified by the [`--overload-decorators`](#--overload-decorators-liststr) configuration option.
0 commit comments