Skip to content

Commit e6cef74

Browse files
committed
Handle overloaded __init__
1 parent 0067fca commit e6cef74

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

flake8_params/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ def visit_ClassDef(self, node: ast.ClassDef) -> None: # noqa: D102
242242

243243
for function in functions_in_body:
244244
if function.name == "__init__":
245+
init_decorators = list(get_decorator_names(function))
246+
if any(d.endswith("overload") for d in init_decorators):
247+
continue
248+
245249
signature_args = list(get_signature_args(function))
246250
break
247251
else:

tests/example_code.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def positional_only(foo, /, bar, baz):
348348

349349

350350
# stdlib
351-
from typing import Tuple
351+
from typing import Optional, Tuple, overload
352352

353353

354354
class MyTuple(Tuple[int, str, int]): # noqa: SLOT001
@@ -418,3 +418,27 @@ def has_underscores(foo, bar, baz_):
418418
:param bar:
419419
:param baz\_:
420420
"""
421+
422+
423+
class FRange:
424+
"""
425+
A class with overloaded __init__.
426+
427+
:param start:
428+
:param stop:
429+
:param step:
430+
"""
431+
432+
@overload
433+
def __init__(self, stop: float) -> None: ...
434+
435+
@overload
436+
def __init__(self, start: float, stop: float, step: float = ...) -> None: ...
437+
438+
def __init__( # type: ignore[misc]
439+
self,
440+
start: Optional[float] = None,
441+
stop: Optional[float] = None,
442+
step: float = 1.0,
443+
) -> None:
444+
pass

0 commit comments

Comments
 (0)