too-few-public-methods / R0903ΒΆ
Message emitted:
Too few public methods (%s/%s)
Description:
Used when class has too few public methods, so be sure it's really worth it.
Problematic code:
class Worm: # [too-few-public-methods]
def __init__(self, name: str, fruit_of_residence: Fruit):
self.name = name
self.fruit_of_residence = fruit_of_residence
def bore(self):
print(f"{self.name} is boring into {self.fruit_of_residence}")
Correct code:
dataclass_and_function.py
:
import dataclasses
@dataclasses.dataclass
class Worm:
name: str
fruit_of_residence: Fruit
def bore(worm: Worm):
print(f"{worm.name} is boring into {worm.fruit_of_residence}")
function.py
:
def bore(fruit: Fruit, worm_name: str):
print(f"{worm_name} is boring into {fruit}")
larger_api.py
:
class Worm:
def __init__(self, name: str, fruit_of_residence: Fruit):
self.name = name
self.fruit_of_residence = fruit_of_residence
def bore(self):
print(f"{self.name} is boring into {self.fruit_of_residence}")
def wiggle(self):
print(f"{self.name} wiggle around wormily.")
Created by the design checker.