Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pylint] Ignore overload in PLR0904 #14730

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import Any, Literal, overload


class Everything:
foo = 1

Expand Down Expand Up @@ -34,6 +37,7 @@ def method8(self):
def method9(self):
pass


class Small:
def __init__(self):
pass
Expand All @@ -58,3 +62,26 @@ def method5(self):

def method6(self):
pass


class SmallWithOverload:
@overload
def method1(self, a: Literal[1]) -> None: ...
@overload
def method1(self, a: Literal[2]) -> None: ...
@overload
def method1(self, a: Literal[3]) -> None: ...
@overload
def method1(self, a: Literal[4]) -> None: ...
@overload
def method1(self, a: Literal[5]) -> None: ...
@overload
def method1(self, a: Literal[6]) -> None: ...
@overload
def method1(self, a: Literal[7]) -> None: ...
@overload
def method1(self, a: Literal[8]) -> None: ...
@overload
def method1(self, a: Literal[9]) -> None: ...

def method1(self, a: Any) -> None: ...
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ pub(crate) fn too_many_public_methods(
.body
.iter()
.filter(|stmt| {
stmt.as_function_def_stmt()
.is_some_and(|node| matches!(visibility::method_visibility(node), Public))
stmt.as_function_def_stmt().is_some_and(|node| {
matches!(visibility::method_visibility(node), Public)
&& !visibility::is_overload(&node.decorator_list, checker.semantic())
})
})
.count();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
---
source: crates/ruff_linter/src/rules/pylint/mod.rs
snapshot_kind: text
---
too_many_public_methods.py:1:1: PLR0904 Too many public methods (10 > 7)
too_many_public_methods.py:4:1: PLR0904 Too many public methods (10 > 7)
|
1 | / class Everything:
2 | | foo = 1
3 | |
4 | | def __init__(self):
5 | | pass
4 | / class Everything:
5 | | foo = 1
6 | |
7 | | def _private(self):
7 | | def __init__(self):
8 | | pass
9 | |
10 | | def method1(self):
10 | | def _private(self):
11 | | pass
12 | |
13 | | def method2(self):
13 | | def method1(self):
14 | | pass
15 | |
16 | | def method3(self):
16 | | def method2(self):
17 | | pass
18 | |
19 | | def method4(self):
19 | | def method3(self):
20 | | pass
21 | |
22 | | def method5(self):
22 | | def method4(self):
23 | | pass
24 | |
25 | | def method6(self):
25 | | def method5(self):
26 | | pass
27 | |
28 | | def method7(self):
28 | | def method6(self):
29 | | pass
30 | |
31 | | def method8(self):
31 | | def method7(self):
32 | | pass
33 | |
34 | | def method9(self):
34 | | def method8(self):
35 | | pass
36 | |
37 | | def method9(self):
38 | | pass
| |____________^ PLR0904
36 |
37 | class Small:
|