From 40b71e6f6dfdafd7417da43ce1d75f8899ed6a54 Mon Sep 17 00:00:00 2001 From: Nathan Marrow Date: Mon, 7 Jan 2019 16:15:27 -0500 Subject: 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). --- pylint/checkers/utils.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'pylint/checkers/utils.py') 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: -- cgit v1.2.1