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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enforce any/all calls #2702

Merged
merged 1 commit into from
Aug 6, 2023
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
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