Skip to content

Commit

Permalink
PLR0902: add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
liushuyu committed Mar 5, 2024
1 parent f4f7c1e commit 20b24f0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@ def __init__(self):
self.secondary_worm_name = "Kim"
self.secondary_worm_type = "Apple maggot"
self.secondary_worm_color = "Whitish"


class Apple(Fruit):
def __init__(self):
# typed assignments
self.a_string: str = "String"
self.a_number: float = 3.1415926


class Banana(Fruit):
# exactly 7 attributes
def __init__(self):
self.attr0: int = 0
self.attr0 = 1
self.attr1, self.attr2 = 1, 2
self.attr2 = 3
self.attr3 = 4

def other_method(self):
self.attr4 = 5
self.attr5 = 6
self.attr6 = 7


class Watermelon(Fruit):
# 8 attributes (4 + 4)
def __init__(self):
self.attr0, self.attr1, self.attr2, self.attr3 = 0, 1, 2, 3

def other_method(self):
self.attr4, self.attr5, self.attr6, self.attr7 = 4, 5, 6, 7
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
too_many_attributes.py:1:7: PLR0902 Too many instance attributes (15/7)
too_many_attributes.py:1:7: PLR0902 Too many instance attributes (13/7)
|
1 | class Fruit:
| ^^^^^ PLR0902
2 | # max of 7 attributes by default, can be configured
3 | self.attr0: int = 0
|


too_many_attributes.py:42:7: PLR0902 Too many instance attributes (8/7)
|
42 | class Watermelon(Fruit):
| ^^^^^^^^^^ PLR0902
43 | # 8 attributes (4 + 4)
44 | def __init__(self):
|

0 comments on commit 20b24f0

Please sign in to comment.