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
Forbid consecutive slices. #2220
Conversation
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.
Thanks!
'a[3:7]', | ||
'a[4][:5]', | ||
'a["hello"][4:]', | ||
'a[1:]["tram"][17:]', |
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.
Let's also test:
a[1][2][3]
a[a[0:1]][a[1:2]][a[2:3]]
@@ -161,6 +162,7 @@ | |||
.. autoclass:: BareRaiseViolation | |||
.. autoclass:: RedundantEnumerateViolation | |||
.. autoclass:: RaiseFromItselfViolation | |||
.. autoclass:: ConsecutiveSlicesViolation |
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.
Looks like it should be after .. autoclass:: KwargsUnpackingInClassDefinitionViolation
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.
Yep, it is an artifact of merging. Will fix it shortly.
|
||
Example:: | ||
|
||
a = [1, 2, 3, 4] |
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 can remove this line. All our examples are as simple as possible.
a = [1, 2, 3, 4] | ||
|
||
# Correct: | ||
a[1:3] |
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 can rename a
with my_list
@@ -17,12 +18,44 @@ | |||
class SubscriptVisitor(base.BaseNodeVisitor): | |||
"""Checks subscripts used in the code.""" | |||
|
|||
_marked_slices: Set[ast.Subscript] = set() |
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.
Is it important to have this as class var? Maybe instance one?
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 has to be always present on an instance so that the generic_visit
method can function even if no consecutive slices were found. Or did I misunderstand your intention?
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Codecov Report
@@ Coverage Diff @@
## master #2220 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 119 119
Lines 6293 6316 +23
Branches 1402 1409 +7
=========================================
+ Hits 6293 6316 +23
Continue to review full report at Codecov.
|
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.
Thank you!
I have made things!
Checklist
CHANGELOG.md
Related issues
馃檹 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.