-
-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Develop violation for pointless starred expressions (#734)
* Develop violation for pointless starred expressions * Fix style of code * Add final decorator for visitor * Fix incorrect docstrings * Refactor of logic for finding useless starred expressions * Fix coding style * Fix coding style * Fix coding style * Change logic of checking starred arguments * Fix coding style * Improve visitor logic * Fix typehints * Fix coding style * Fix coding style * Fix docstring in new violation * Fix noqa test * Add feature description to CHANGELOG
- Loading branch information
Showing
6 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,6 +184,7 @@ | |
'WPS514': 1, | ||
'WPS515': 1, | ||
'WPS516': 1, | ||
'WPS517': 0, | ||
|
||
'WPS600': 1, | ||
'WPS601': 1, | ||
|
81 changes: 81 additions & 0 deletions
81
tests/test_visitors/test_ast/test_statements/test_pointless_starred.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.violations.refactoring import ( | ||
PointlessStarredViolation, | ||
) | ||
from wemake_python_styleguide.visitors.ast.statements import ( | ||
PointlessStarredVisitor, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
'print(*[])', | ||
'print(*())', | ||
'print(*{})', # noqa: P103 | ||
'print(**{})', # noqa: P103 | ||
'print(*[1, 2])', | ||
'print(*(1, 2))', | ||
'print(*{1, 2})', | ||
'print(**{"end": " "})', | ||
]) | ||
def test_pointless_starred_arg( | ||
assert_errors, | ||
parse_ast_tree, | ||
default_options, | ||
code, | ||
): | ||
"""Testing that pointless starred expression is detected.""" | ||
tree = parse_ast_tree(code) | ||
|
||
visitor = PointlessStarredVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [PointlessStarredViolation]) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
'print(*[], **{})', # noqa: P103 | ||
'print(*[], **{"1": 1})', # noqa: P103 | ||
'print(*[1], **{})', # noqa: P103 | ||
'print(*[1], **{"end": " "})', | ||
]) | ||
def test_pointless_starred_arg_and_keyword( | ||
assert_errors, | ||
parse_ast_tree, | ||
default_options, | ||
code, | ||
): | ||
"""Testing that pointless starred expression is detected.""" | ||
tree = parse_ast_tree(code) | ||
|
||
visitor = PointlessStarredVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors( | ||
visitor, | ||
[PointlessStarredViolation, PointlessStarredViolation], | ||
) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
""" | ||
_list = [1, 2] | ||
_dict = {"end": " "} | ||
print(*_list, **_dict) | ||
""", | ||
]) | ||
def test_useful_starred_arg_and_keyword( | ||
assert_errors, | ||
parse_ast_tree, | ||
default_options, | ||
code, | ||
): | ||
"""Testing that pointless starred expression is detected.""" | ||
tree = parse_ast_tree(code) | ||
|
||
visitor = PointlessStarredVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters