summaryrefslogtreecommitdiff
path: root/pylint/checkers/utils.py
diff options
context:
space:
mode:
authorNathan Marrow <nmarrow@google.com>2019-01-07 16:15:27 -0500
committerClaudiu Popa <pcmanticore@gmail.com>2019-03-22 09:59:09 +0100
commit40b71e6f6dfdafd7417da43ce1d75f8899ed6a54 (patch)
tree2a67b8c0e07c71c75fb8f68de6d9548b5bc32bfe /pylint/checkers/utils.py
parent3ff17ae9e32ad1ede7f5963d185c5c9f35ff8ca0 (diff)
downloadpylint-git-40b71e6f6dfdafd7417da43ce1d75f8899ed6a54.tar.gz
Don't recurse in inherit_from_std_ex
Commit 79c71de changed inherit_from_std_ex to pass recurs=True to the call to ancestors. Since the ancestors call now recurses, there is no need for the inherit_from_std_ex function to recurse as well, especially since ancestors handles circular references (A inherits from B which inherits from A).
Diffstat (limited to 'pylint/checkers/utils.py')
-rw-r--r--pylint/checkers/utils.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index 38dca2a38..4d7efe249 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -671,14 +671,17 @@ def inherit_from_std_ex(node: astroid.node_classes.NodeNG) -> bool:
Return true if the given class node is subclass of
exceptions.Exception.
"""
- if (
- node.name in ("Exception", "BaseException")
- and node.root().name == EXCEPTIONS_MODULE
- ):
- return True
if not hasattr(node, "ancestors"):
- return False
- return any(inherit_from_std_ex(parent) for parent in node.ancestors(recurs=True))
+ ancestors = []
+ else:
+ ancestors = node.ancestors()
+ for ancestor in itertools.chain([node], ancestors):
+ if (
+ ancestor.name in ("Exception", "BaseException")
+ and ancestor.root().name == EXCEPTIONS_MODULE
+ ):
+ return True
+ return False
def error_of_type(handler: astroid.ExceptHandler, error_type) -> bool: