Closed
Description
Current problem
Here is a function from Astroid:
def is_from_decorator(node):
"""Return True if the given node is the child of a decorator"""
for parent in node.node_ancestors():
if isinstance(parent, Decorators):
return True
return False
What does it do? Evidently it loops over the node's ancestors and returns whether any of them are decorators. Well, why not just say that?
def is_from_decorator(node):
"""Return True if the given node is the child of a decorator"""
return any(isinstance(parent, Decorators)
for parent in node.node_ancestors())
Desired solution
The any
and all
functions are generally shorter and more declarative than explicit looping, so add a check to suggest using them when appropriate.
Implmenting this check so as to avoid too many false positives might be an interesting challenge!
Additional context
No response