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

Restrict the maximum number of base classes aka mixins #264 #278

Merged
merged 3 commits into from
Oct 20, 2018
Merged

Restrict the maximum number of base classes aka mixins #264 #278

merged 3 commits into from
Oct 20, 2018

Conversation

nsimonoff
Copy link
Contributor

@nsimonoff nsimonoff commented Oct 19, 2018

I have made things!

Checklist

  • I have double checked that there are no unrelated changes in this pull request (old patches, accidental config files, etc)
  • I have created at least one test case for the changes I have made
  • I have updated the documentation for the changes I have made
  • I have added my changes to the CHANGELOG.md

Related issues

Closes #264

@coveralls
Copy link

coveralls commented Oct 19, 2018

Pull Request Test Coverage Report for Build 538

  • 11 of 11 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 530: 0.0%
Covered Lines: 1420
Relevant Lines: 1420

💛 - Coveralls

Copy link
Member

@sobolevn sobolevn left a 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove the tabulation.

Copy link
Member

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,
Copy link
Member

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',
Copy link
Member

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,
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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,
Copy link
Member

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

Copy link
Member

@sobolevn sobolevn left a 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
Copy link
Member

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
Copy link
Member

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.
Copy link
Member

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``.

Copy link
Member

@sobolevn sobolevn left a 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 sobolevn merged commit 6e22cfd into wemake-services:master Oct 20, 2018
@nsimonoff
Copy link
Contributor Author

@sobolevn Used it personally. I am new in python, and this is good opportunity to learn it.

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

Successfully merging this pull request may close these issues.

3 participants