Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Semantic versioning in our case means:
- Fixes the false positive `WPS617` by assigning a function that receives a lambda expression as a parameter.
- Fixes false positive `WPS430` for whitelisted nested functions, #3589

### Removals

- **Breaking**: Removes `WPS354`, because it is inconsistent with async code, #3601


## 1.5.0

Expand Down
4 changes: 0 additions & 4 deletions tests/fixtures/noqa/noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,6 @@ def wrong_yield_from():
yield from [] # noqa: WPS353


def consecutive_yields():
yield 1
yield 2 # noqa: WPS354

if 'key' in some_dict:
my_print(some_dict['key']) # noqa: WPS529
my_print(other_dict[1.0]) # noqa: WPS449
Expand Down
2 changes: 1 addition & 1 deletion tests/test_checker/test_noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
'WPS351': 0, # disabled since 1.0.0
'WPS352': 0, # disabled since 1.0.0
'WPS353': 1,
'WPS354': 1,
'WPS354': 0, # disabled since 1.6.0
'WPS355': 0, # disabled since 1.0.0
'WPS356': 1,
'WPS357': 0, # logically unacceptable.
Expand Down

This file was deleted.

4 changes: 4 additions & 0 deletions wemake_python_styleguide/violations/consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -2086,11 +2086,15 @@ class ConsecutiveYieldsViolation(ASTViolation):
It can be easily changed to ``yield from (...)`` format.

.. versionadded:: 0.13.0
.. versionchanged:: 1.6.0
No longer produced, kept here for historic reasons.
It is inconsistent with async code.

"""

error_template = 'Found consecutive `yield` expressions'
code = 354
disabled_since = '1.6.0'


@final
Expand Down
41 changes: 0 additions & 41 deletions wemake_python_styleguide/visitors/ast/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
WrongKeywordViolation,
)
from wemake_python_styleguide.violations.consistency import (
ConsecutiveYieldsViolation,
InconsistentReturnViolation,
InconsistentYieldViolation,
IncorrectYieldFromTargetViolation,
Expand Down Expand Up @@ -204,13 +203,6 @@ def _check_variable_definitions(self, node: ast.withitem) -> None:


@final
@alias(
'visit_any_function',
(
'visit_FunctionDef',
'visit_AsyncFunctionDef',
),
)
class GeneratorKeywordsVisitor(BaseNodeVisitor):
"""Checks how generators are defined and used."""

Expand All @@ -223,27 +215,12 @@ class GeneratorKeywordsVisitor(BaseNodeVisitor):
ast.GeneratorExp,
)

def __init__(self, *args, **kwargs) -> None:
"""Here we store the information about ``yield`` locations."""
super().__init__(*args, **kwargs)
self._yield_locations: dict[int, ast.Expr] = {}

def visit_any_function(self, node: AnyFunctionDef) -> None:
"""Checks for consecutive ``yield`` nodes."""
self._check_consecutive_yields(node)
self.generic_visit(node)

def visit_YieldFrom(self, node: ast.YieldFrom) -> None:
"""Checks ``yield from`` nodes."""
self._check_yield_from_type(node)
self._check_yield_from_empty(node)
self.generic_visit(node)

def _check_consecutive_yields(self, node: AnyFunctionDef) -> None:
for sub in ast.walk(node):
if isinstance(sub, ast.Expr) and isinstance(sub.value, ast.Yield):
self._yield_locations[sub.value.lineno] = sub

def _check_yield_from_type(self, node: ast.YieldFrom) -> None:
if not isinstance(node.value, self._allowed_nodes):
self.add_violation(IncorrectYieldFromTargetViolation(node))
Expand All @@ -252,24 +229,6 @@ def _check_yield_from_empty(self, node: ast.YieldFrom) -> None:
if isinstance(node.value, ast.Tuple) and not node.value.elts:
self.add_violation(IncorrectYieldFromTargetViolation(node))

def _post_visit(self) -> None:
previous_line: int | None = None
previous_parent: ast.AST | None = None

for line, node in self._yield_locations.items():
parent = get_parent(node)

if (
previous_line is not None
and line - 1 == previous_line
and previous_parent == parent
):
self.add_violation(ConsecutiveYieldsViolation(node.value))
break

previous_line = line
previous_parent = parent


@final
class ConstantKeywordVisitor(BaseNodeVisitor):
Expand Down