Rework WPS332: allow := in comprehensions#3129
Rework WPS332: allow := in comprehensions#3129sobolevn merged 17 commits intowemake-services:masterfrom
Conversation
| """We use this visitor to find walrus operators and ban them.""" | ||
| def __init__(self, *args, **kwargs) -> None: | ||
| super().__init__(*args, **kwargs) | ||
| self._inside_comprehension = False |
There was a problem hiding this comment.
I think that it would be easier to use walk.get_closest_parent and expect a ast.comprehension
|
@sobolevn next attempt. Removed ast.comprehension and added tuple with concrete comprehesions. Look likes clearly |
| closest = walk.get_closest_parent( | ||
| node, | ||
| ( | ||
| ast.ListComp, |
There was a problem hiding this comment.
Please, move this to be a class level constant.
There was a problem hiding this comment.
Do you mean a whole tuple with possible comprehensions?
There was a problem hiding this comment.
Yes, like we do with other ClassVar[AnyNodes]
| ) | ||
| ) | ||
|
|
||
| if closest is None: |
There was a problem hiding this comment.
Let's use early returns
| if closest is None: | |
| if closest is not None: | |
| return |
| ) -> None: | ||
| """Disallows walrus ``:=`` operator.""" | ||
| self.add_violation(consistency.WalrusViolation(node)) | ||
| """Disallows walrus ``:=`` operator outside comprehension.""" |
There was a problem hiding this comment.
| """Disallows walrus ``:=`` operator outside comprehension.""" | |
| """Disallows walrus ``:=`` operator outside comprehensions.""" |
|
Please, fix |
Hmmm... One moment. |
|
Merged all new changes from master. Can try again? =) |
| """Disallows walrus ``:=`` operator.""" | ||
| self.add_violation(consistency.WalrusViolation(node)) | ||
| """Disallows walrus ``:=`` operator outside comprehensions.""" | ||
| closest = walk.get_closest_parent( |
There was a problem hiding this comment.
Please, create a method for that. Let's call it _check_walrus_in_comprehension
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3129 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 117 117
Lines 6001 6007 +6
Branches 883 884 +1
=========================================
+ Hits 6001 6007 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.mdCloses Rework
WPS332: allow:=in comprehensions #3121