-
-
Notifications
You must be signed in to change notification settings - Fork 378
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
Forbid consecutive slices #2064
Comments
Hi! I'm new and I would like to work on this issue. May I ask for more info? |
@Edald123 yes, sure! Thanks! Please, take a look at https://github.com/wemake-services/wemake-python-styleguide/blob/master/CONTRIBUTING.md |
Thank you! I'm on it |
Hi, I have already checked the resources from the contributing file. I would like to check if my approach would be correct or not. I understood that I would have to create a new visitor and violation, not necessarily a new flake8 plugin. From there I would choose an ast based visitor using the already created one: BaseNodeVisitor. Then I would write only a violation and check logic. Would this be a good approach taking into account the type of rule of the issue? Thaks! |
Correct.
Not a plugin, correct!
Yes 👍
Correct! I will be glad to review your code and help with any questions you have. |
Thank you!, I will be sharing my progress then. |
Hi! |
Sure! Thanks! @Edald123 do you need my help? |
Hi! So far we have implemented a solution in wemake_python_styleguide/visitors/ast/subscripts.py. def _check_consecutive(self, node: ast.Subscript) -> None:
"""Check if subscript node has a slice and a subscript"""
if isinstance(node.slice, ast.Slice) and isinstance(node.value, ast.Subscript):
self.add_violation(consistency.ForbidConsecutiveSlicesViolation(node)) Our implementation is passing some tests but others not. no_consecutive = """
a = [1, 2, 3, 4]
b = a[1:]
"""
no_consecutive_visit = """
a = [1, 2, 3, 4]
b = a[1:][2]
"""
no_slicing = """
a = [1, 2, 3, 4]
b = a[1]
"""
no_slicing_double = """
a = [1, [5, 6, 7], 3, 4]
b = a[1][3]
"""
no_slicing_triple = """
a = [1, [5, 6, 7, [8, 9, 10]], 3, 4]
b = a[1][3][1]
"""
consecutive_double = """
a = [1, 2, 3, 4]
b = a[1:][2:]
"""
consecutive_triple = """
a = [1, 2, 3, 4, 5, 6]
b = a[1:][2:][:2]
"""
consecutive_plus = """
a = [1, [5, 6, 7, 8, 9, 10], 3, 4]
b = a[1][2:][:4]
"""
no_consecutive_for_slices = """
a = [1, [5, 6, 7, [8, [1, 2, 3, 4], 10]], 3, 4]
for i in a[1][3][1]:
print(i)
"""
consecutive_for = """
a = [1, [5, 6, 7, [8, [1, 2, 3, 4], 10]], 3, 4]
for i in a[1][:4][1:]:
print(i)
""" The tests that are not supposed to raise errors are: The tests that are supposed to raise an error (violation) are: The problem is that these 3 tests are raising 2 errors instead of 1 so they fail: |
Hey, send a work-in-progress PR! It would be super helpful! 👍 |
Hi! |
Hi @sobolevn I am new to open source and wanted to get started with contributing to good first issues, but i am facing a little difficulty in how to get myself more invoved in the project. Can you suggest me what steps do i need to follow after going through contributing docs. |
Hi @Manthanjain! Sure! Read this:
But, looks like someone else is working on this issue, feel free to choose any other one. |
Is this issue still being worked on? Can I take it over if it's not? |
We have an unofficial policy to reassign tasks after a ling period of inactivity. Thanks a lot to everyone who wanted to help! I appreciate it ❤️ |
Oups, sorry! I've totally missed it (because it was not linked to this issue). |
Rule request
Thesis
We should forbid consecutive slices.
Reasoning
Consider this code:
What it does?
a[1:]
is[2, 3, 4]
[2, 3, 4][:2]
is[2, 3]
It is much more readable and effective to use
Related https://twitter.com/m_ou_se/status/1403426221367627777
The text was updated successfully, but these errors were encountered: