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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract new violation - WPS450 from WPS436 #1118

Merged
merged 4 commits into from Jan 26, 2020

Conversation

skarzi
Copy link
Collaborator

@skarzi skarzi commented Jan 22, 2020

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: #1113

馃檹 Please, if you or your company is finding wemake-python-styleguide valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/wemake-python-styleguide. As a thank you, your profile/company logo will be added to our main README which receives hundreds of unique visitors per day.

@coveralls
Copy link

coveralls commented Jan 22, 2020

Pull Request Test Coverage Report for Build 2511

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

Totals Coverage Status
Change from base Build 2506: 0.0%
Covered Lines: 5050
Relevant Lines: 5050

馃挍 - 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.

Thanks! There are several minor questions and we are good to go!

Great work! 馃殌

DottedRawImportViolation
NestedImportViolation
ProtectedModuleViolation,
SameAliasImportViolation
VagueImportViolation,
Copy link
Member

Choose a reason for hiding this comment

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

Extra ,

DottedRawImportViolation
NestedImportViolation
ProtectedModuleViolation,
Copy link
Member

Choose a reason for hiding this comment

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

Extra ,

@@ -27,7 +28,7 @@
ErrorCallback = Callable[[BaseViolation], None] # TODO: alias and move


@final
@final # noqa: WPS214
Copy link
Member

Choose a reason for hiding this comment

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

Can we do something with this violation here?

Can we refactor this class to be more simple? Or just split it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the latest commit I splitted this validator into 3 classes:

  • ast.Import validator
  • ast.ImportFrom validator
  • base class for both above mentioned validators

If you have any ideas how to make it clearer please let me know.

"""Validator of ``ast.Import`` nodes."""

def validate(self, node: AnyImport) -> None:
node = cast(ast.Import, node)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I dislike this casting :D
Do you know if there is any better way to type such strict subclasses which provides implementation only for one type of the type from Union defined in base class?

"""Validator of ``ast.Import`` nodes."""

def validate(self, node: AnyImport) -> None:
node = cast(ast.Import, node)
Copy link
Member

Choose a reason for hiding this comment

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

We try not use cast. It should be a bug in Python typing to actually use it.
Can you please refactor this place once again?

Copy link
Collaborator Author

@skarzi skarzi Jan 22, 2020

Choose a reason for hiding this comment

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

Sure, but to do that I need to use AnyImport everywhere instead of concrete import's type that is being validated in given method, is that ok?

e,g def _check_dotted_raw_import(self, node: AnyImport) -> None: instead of def _check_dotted_raw_import(self, node: ast.Import) -> None:

@@ -39,30 +40,18 @@ def __init__(
self._error_callback = error_callback
self._options = options

def check_nested_import(self, node: AnyImport) -> None:
@abc.abstractmethod
def validate(self, node: AnyImport):
Copy link
Member

Choose a reason for hiding this comment

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

-> None

Copy link
Member

@sobolevn sobolevn Jan 22, 2020

Choose a reason for hiding this comment

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

We can just name this method differently. Like _validate_any_import and then call it in specific .validate method instead of super().validate()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, but then we need to resign from declaring .validate() as abstractmethod and just provide this method in 2 concrete validators to satisfy mypy, is that what you suggest?

Copy link
Member

Choose a reason for hiding this comment

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

Yes 馃憤

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.

Thanks a lot! Awesome job.

@sobolevn sobolevn merged commit a7408ca into wemake-services:master Jan 26, 2020
@skarzi skarzi deleted the issue-1113 branch January 26, 2020 12:34
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.

Split WPS436 into two rules
3 participants