-
-
Notifications
You must be signed in to change notification settings - Fork 381
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
Restrict the maximum number of base classes aka mixins #264 #278
Conversation
Pull Request Test Coverage Report for Build 538
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor issue before merging this!
This is an awesome feature. I am very glad you have nailed it!
Thanks.
from wemake_python_styleguide.visitors.ast.classes import WrongClassVisitor | ||
|
||
correct_count = """ | ||
class CorrectClassName(FirstParentClass, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, remove the tabulation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also use different type of (...)
.
It should be like so:
class Some(
Parent1,
Parent2,
):
|
||
|
||
too_many_count = """ | ||
class SomeClassName(FirstParentClass, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same about tabulation and ()
@@ -181,6 +181,12 @@ class Configuration(object): | |||
'Maximum number of conditions in a `if` or `while` node.', | |||
), | |||
|
|||
_Option( | |||
'--max-classes-number', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be --max-base-classes
@@ -181,6 +181,12 @@ class Configuration(object): | |||
'Maximum number of conditions in a `if` or `while` node.', | |||
), | |||
|
|||
_Option( | |||
'--max-classes-number', | |||
defaults.MAX_CLASSES_NUMBER, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be MAX_BASE_CLASSES
.
Reasoning: | ||
It is almost never possible to navigate | ||
to the desired method of a parent class | ||
when you need it with multiple mixin. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mixins
It is almost never possible to navigate | ||
to the desired method of a parent class | ||
when you need it with multiple mixin. | ||
It is hard to understand mro and super calls. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mro
and super
should be wrapped with double ``
class SomeClassName(FirstParentClass, SecondParentClass): ... | ||
|
||
# Wrong: | ||
class SomeClassName(FirstParentClass, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same about ()
applies here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost ready!
class CorrectClassName( | ||
FirstParentClass, | ||
SecondParentClass, | ||
ThirdParentClass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a trailing comma
SecondParentClass, | ||
ThirdParentClass, | ||
CustomClass, | ||
AddedClass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a trailing comma
when you need it with multiple mixin. | ||
It is hard to understand mro and super calls. | ||
when you need it with multiple mixins. | ||
It is hard to understand 'mro' and 'super' calls. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, use double `` to wrap mro
and `super`. Like here:
This rule is configurable with ``--max-module-members``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thank you!
@geoc0ld do you use this tool personally or with your company?
@sobolevn Used it personally. I am new in python, and this is good opportunity to learn it. |
I have made things!
Checklist
CHANGELOG.md
Related issues
Closes #264