Skip to content

Commit

Permalink
enforce any/all calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchidonut0 committed Aug 5, 2023
1 parent 5bb6dd8 commit a09bb3e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 13 deletions.
5 changes: 1 addition & 4 deletions wemake_python_styleguide/logic/tree/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ def is_first_argument(node: AnyFunctionDefAndLambda, name: str) -> bool:

def is_generator(node: AnyFunctionDef) -> bool:
"""Tells whether a given function is a generator."""
for body_item in node.body:
if is_contained(node=body_item, to_check=(Yield, YieldFrom)):
return True
return False
return any(is_contained(body, (Yield, YieldFrom)) for body in node.body)


def get_function_exit_nodes(node: AnyFunctionDef) -> _ControlTransferIterable:
Expand Down
6 changes: 1 addition & 5 deletions wemake_python_styleguide/logic/tree/loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ def _does_loop_contain_node(
if loop is None:
return False

for inner_node in ast.walk(loop):
# We are checking this specific node, not just any `break`:
if to_check is inner_node:
return True
return False
return any(to_check is inner_node for inner_node in ast.walk(loop))


def has_break(
Expand Down
5 changes: 1 addition & 4 deletions wemake_python_styleguide/logic/walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ def is_contained(
Goes down by the tree to check all children.
"""
for child in ast.walk(node):
if isinstance(child, to_check):
return True
return False
return any(isinstance(child, to_check) for child in ast.walk(node))


def get_closest_parent(
Expand Down

0 comments on commit a09bb3e

Please sign in to comment.