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

Forbid consecutive slices. #2220

Merged
merged 5 commits into from Oct 11, 2021
Merged

Forbid consecutive slices. #2220

merged 5 commits into from Oct 11, 2021

Conversation

lensvol
Copy link
Collaborator

@lensvol lensvol commented Oct 11, 2021

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

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

@lensvol lensvol requested a review from sobolevn October 11, 2021 10:32
@lensvol lensvol self-assigned this Oct 11, 2021
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[3:7]',
'a[4][:5]',
'a["hello"][4:]',
'a[1:]["tram"][17:]',
Copy link
Member

Choose a reason for hiding this comment

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

Let's also test:

  1. a[1][2][3]
  2. a[a[0:1]][a[1:2]][a[2:3]]

@@ -161,6 +162,7 @@
.. autoclass:: BareRaiseViolation
.. autoclass:: RedundantEnumerateViolation
.. autoclass:: RaiseFromItselfViolation
.. autoclass:: ConsecutiveSlicesViolation
Copy link
Member

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

Copy link
Collaborator Author

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

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

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

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?

Copy link
Collaborator Author

@lensvol lensvol Oct 11, 2021

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?

@codecov
Copy link

codecov bot commented Oct 11, 2021

Codecov Report

Merging #2220 (4cc5c3c) into master (6b5907e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #2220   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          119       119           
  Lines         6293      6316   +23     
  Branches      1402      1409    +7     
=========================================
+ Hits          6293      6316   +23     
Impacted Files Coverage 螖
...ake_python_styleguide/violations/best_practices.py 100.00% <100.00%> (酶)
...emake_python_styleguide/visitors/ast/subscripts.py 100.00% <100.00%> (酶)

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 6b5907e...4cc5c3c. Read the comment docs.

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.

Thank you!

@sobolevn sobolevn merged commit ba51ad4 into master Oct 11, 2021
@delete-merged-branch delete-merged-branch bot deleted the 2064-consecutive-slices branch October 11, 2021 11:13
This was referenced Oct 11, 2021
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.

None yet

2 participants