Skip to content

Commit 34cf98e

Browse files
committed
Ignore first parameter of __new__.
1 parent bb96303 commit 34cf98e

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

flake8_params/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ def _visit_function(self, node: Union[ast.FunctionDef, ast.AsyncFunctionDef]) ->
202202
signature_args = list(get_signature_args(node))
203203
decorators = list(get_decorator_names(node))
204204

205+
if node.name == "__new__":
206+
# Remove 'cls' etc.
207+
signature_args.pop(0)
208+
205209
error = check_params(signature_args, docstring_args, decorators)
206210
if not error:
207211
self.generic_visit(node)

tests/example_code.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,19 @@ def positional_only(foo, /, bar, baz):
345345
:param bar:
346346
:param baz:
347347
"""
348+
349+
350+
# stdlib
351+
from typing import Tuple
352+
353+
354+
class MyTuple(Tuple[int, str, int]): # noqa: SLOT001
355+
356+
def __new__(cls, a: int, b: str, c: int = 0) -> "MyTuple":
357+
"""
358+
Create a new :class:`~.MyTuple`.
359+
360+
:rtype: :class:`~.MyTuple`.
361+
"""
362+
363+
return super().__new__((a, b, c)) # type: ignore[arg-type]

tests/test_flake8_params_/test_plugin.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
278:1: PRM003 Extra parameters in docstring: bar
1818
292:0: PRM002 Missing parameters in docstring: *baz
1919
311:0: PRM002 Missing parameters in docstring: **baz
20+
356:1: PRM002 Missing parameters in docstring: a b c

0 commit comments

Comments
 (0)