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

Add __init_subclass__ to the order of methods in WPS338 #2410

Closed
Bobronium opened this issue Apr 29, 2022 · 1 comment · Fixed by #2411
Closed

Add __init_subclass__ to the order of methods in WPS338 #2410

Bobronium opened this issue Apr 29, 2022 · 1 comment · Fixed by #2411
Labels
rule request Adding a new rule

Comments

@Bobronium
Copy link
Contributor

Bobronium commented Apr 29, 2022

Rule request

Thesis

__init_subclass__ (PEP 487) should be added to WPS338 order. The resulting list would look like this:

  • __init_subclass__
  • __new__
  • __init__
  • __call__
  • __await__
  • public and magic methods
  • protected methods
  • private methods (we discourage using them)

Reasoning

In current order I see that construction and initialisation methods are given priority and ordered from instance construction to instance initialisation.

Chronologically, before all that come class construction and its initialisation. First happens in meta class, second can also be done in __init_subclass__. Therefore it naturally should come before class __new__ and __init__ methods.

Second thoughts

It might be worth considering doing the same with __class_getitem__, since it mostly used for generics construction. But since it might not be even that interesting from user perspective, I'm hesitant at proposing it.

It also should be possible to ignore specific methods by placing #noqa WPS338 at the line of their definition. But that means that reporting will also be done per method instead of current per class reporting, which can be both good (you can see what method is causing the error) and bad (there may be too many errors per class)

@Bobronium Bobronium added the rule request Adding a new rule label Apr 29, 2022
@sobolevn
Copy link
Member

I agree, please, send a PR ;)

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

Successfully merging a pull request may close this issue.

2 participants