Skip to content

Commit

Permalink
allow decorated and subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
diceroll123 committed Jan 22, 2024
1 parent 366bd8e commit 40bc3c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from dataclasses import dataclass


class Point: # PLR0903
def __init__(self, x: float, y: float) -> None:
Expand All @@ -13,3 +15,16 @@ def __init__(self, top_left: Point, bottom_right: Point) -> None:

def area(self) -> float:
...


@dataclass
class Circle: # OK
center: Point
radius: float

def area(self) -> float:
...


class CustomException(Exception): # OK
...
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ pub(crate) fn too_few_public_methods(
class_def: &ast::StmtClassDef,
min_methods: usize,
) {
// allow decorated classes
if !class_def.decorator_list.is_empty() {
return;
}

// allow classes with base classes
if class_def.arguments.is_some() {
return;
}

let methods = class_def
.body
.iter()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
too_few_public_methods.py:4:1: PLR0903 Too few public methods (1 < 2)
too_few_public_methods.py:6:1: PLR0903 Too few public methods (1 < 2)
|
4 | / class Point: # PLR0903
5 | | def __init__(self, x: float, y: float) -> None:
6 | | self.x = x
7 | | self.y = y
6 | / class Point: # PLR0903
7 | | def __init__(self, x: float, y: float) -> None:
8 | | self.x = x
9 | | self.y = y
| |__________________^ PLR0903
|

Expand Down

0 comments on commit 40bc3c0

Please sign in to comment.