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

[New rules request] Empty class and class with two methods, one of which is init #11763

Closed
Rizhiy opened this issue Jun 5, 2024 · 1 comment

Comments

@Rizhiy
Copy link

Rizhiy commented Jun 5, 2024

Hi, not sure if this is the correct place, please point me in the right direction if not.
I've recently re-watched a good talk on not writing too many classes and was wondering if it is possible to implement a few recommendations giver there as rules.

Empty class rule: warn when the class just subclasses another while not doing anything, e.g.:

class MyDict(dict):
	pass

Class with two methods, one of which is __init__: warn when a class has only two methods, one of which is __init__, e.g.:

class Greeting:
    def __init__(self, greeting: str = "Hello") -> None:
        self._greeting = greeting

    def greet(self, name) -> None:
        print(f"{self._greeting} {name}!")

I did a quick search through existing rules, but couldn't find anything relevant.

@Rizhiy Rizhiy changed the title [New rules request] Empty class and Class with two methods one of which is init [New rules request] Empty class and class with two methods, one of which is init Jun 5, 2024
@charliermarsh
Copy link
Member

I think this is roughly what's implemented in #9601. I might suggest chiming in on or watching that PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants