summaryrefslogtreecommitdiff
path: root/astroid
diff options
context:
space:
mode:
authorNick Drozd <nicholasdrozd@gmail.com>2021-11-27 10:25:01 -0500
committerGitHub <noreply@github.com>2021-11-27 16:25:01 +0100
commit813aab5069f55eebf501ea000a46fc39a09956a8 (patch)
tree54a68b31e346165c75c9e89b7cf76e288319ccb1 /astroid
parent47e860f7d5c73d53de77e7c450535e709e5ef99e (diff)
downloadastroid-git-813aab5069f55eebf501ea000a46fc39a09956a8.tar.gz
Upgrade to pylint 2.12 and enable ``for_any_all`` checker (#1277)
* Enable for_any_all check * Upgrade to pylint 2.12 in pre-commit configuration * Fix new Pylint warnings * Upgrade the regex for Mixin Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'astroid')
-rw-r--r--astroid/brain/brain_numpy_utils.py11
-rw-r--r--astroid/modutils.py6
-rw-r--r--astroid/nodes/node_classes.py17
-rw-r--r--astroid/nodes/node_ng.py7
-rw-r--r--astroid/nodes/scoped_nodes.py6
5 files changed, 15 insertions, 32 deletions
diff --git a/astroid/brain/brain_numpy_utils.py b/astroid/brain/brain_numpy_utils.py
index 97c88e3f..96713850 100644
--- a/astroid/brain/brain_numpy_utils.py
+++ b/astroid/brain/brain_numpy_utils.py
@@ -59,13 +59,10 @@ def _is_a_numpy_module(node: Name) -> bool:
potential_import_target = [
x for x in node.lookup(module_nickname)[1] if isinstance(x, Import)
]
- for target in potential_import_target:
- if ("numpy", module_nickname) in target.names or (
- "numpy",
- None,
- ) in target.names:
- return True
- return False
+ return any(
+ ("numpy", module_nickname) in target.names or ("numpy", None) in target.names
+ for target in potential_import_target
+ )
def looks_like_numpy_member(member_name: str, node: NodeNG) -> bool:
diff --git a/astroid/modutils.py b/astroid/modutils.py
index e39c6813..ef8b39da 100644
--- a/astroid/modutils.py
+++ b/astroid/modutils.py
@@ -555,10 +555,8 @@ def is_standard_module(modname, std_path=None):
return False
if std_path is None:
std_path = STD_LIB_DIRS
- for path in std_path:
- if filename.startswith(_cache_normalize_path(path)):
- return True
- return False
+
+ return any(filename.startswith(_cache_normalize_path(path)) for path in std_path)
def is_relative(modname, from_file):
diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py
index 52698943..295f7d8c 100644
--- a/astroid/nodes/node_classes.py
+++ b/astroid/nodes/node_classes.py
@@ -2759,10 +2759,7 @@ class ExceptHandler(mixins.MultiLineBlockMixin, mixins.AssignTypeMixin, Statemen
"""
if self.type is None or exceptions is None:
return True
- for node in self.type._get_name_nodes():
- if node.name in exceptions:
- return True
- return False
+ return any(node.name in exceptions for node in self.type._get_name_nodes())
class ExtSlice(NodeNG):
@@ -3724,10 +3721,9 @@ class Raise(Statement):
"""
if not self.exc:
return False
- for name in self.exc._get_name_nodes():
- if name.name == "NotImplementedError":
- return True
- return False
+ return any(
+ name.name == "NotImplementedError" for name in self.exc._get_name_nodes()
+ )
def get_children(self):
if self.exc is not None:
@@ -5571,10 +5567,7 @@ def const_factory(value):
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
+ return any(isinstance(parent, Decorators) for parent in node.node_ancestors())
def _get_if_statement_ancestor(node: NodeNG) -> Optional[If]:
diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py
index 85df0cc5..b871aa88 100644
--- a/astroid/nodes/node_ng.py
+++ b/astroid/nodes/node_ng.py
@@ -276,10 +276,7 @@ class NodeNG:
False otherwise.
:rtype: bool
"""
- for parent in node.node_ancestors():
- if self is parent:
- return True
- return False
+ return any(self is parent for parent in node.node_ancestors())
@overload
def statement(
@@ -448,7 +445,7 @@ class NodeNG:
We need this method since not all nodes have :attr:`lineno` set.
"""
line = self.lineno
- _node: Optional[NodeNG] = self
+ _node: Optional[NodeNG] = self # pylint: disable = used-before-assignment
try:
while line is None:
_node = next(_node.get_children())
diff --git a/astroid/nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes.py
index 46aca3d3..25824d98 100644
--- a/astroid/nodes/scoped_nodes.py
+++ b/astroid/nodes/scoped_nodes.py
@@ -2398,10 +2398,8 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, node_classes.Statement
"""
if self.qname() == type_name:
return True
- for anc in self.ancestors(context=context):
- if anc.qname() == type_name:
- return True
- return False
+
+ return any(anc.qname() == type_name for anc in self.ancestors(context=context))
def _infer_type_call(self, caller, context):
try: