summaryrefslogtreecommitdiff
path: root/pylint/checkers/utils.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2019-02-19 09:13:07 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2019-02-19 09:21:45 +0100
commit1ae9fcc6b1f83bad403da4f6cc3e69ddb94d49d4 (patch)
tree0f4a9a51163cb99c292a7a149dedac48acfc09b5 /pylint/checkers/utils.py
parent5b2354306e7e608ca02479edd99e5255d13bd0fa (diff)
downloadpylint-git-1ae9fcc6b1f83bad403da4f6cc3e69ddb94d49d4.tar.gz
Protect against `NonDeducibleTypeHierarchy` when calling semi-private `is_subtype`
`astroid.helpers.is_subtype` raises `NonDeducibleTypeHierarchy` when it cannot infer the base classes of the given types, but that makes sense in its context given that the method is mostly used to inform the inference process about the hierarchy of classes. Doesn't make that much sense for ``pylint`` itself, which is why we're handling the exception here, rather than in ``astroid`` Close PyCQA/astroid#644
Diffstat (limited to 'pylint/checkers/utils.py')
-rw-r--r--pylint/checkers/utils.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index 3cc292115..b4129389f 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -40,6 +40,7 @@ from typing import Optional, Iterable, Tuple, Callable, Set, Union, Match, Dict,
import _string # pylint: disable=wrong-import-position, wrong-import-order
import astroid
+from astroid.exceptions import _NonDeducibleTypeHierarchy
from astroid import bases as _bases
from astroid import scoped_nodes
@@ -1202,6 +1203,9 @@ def is_subclass_of(child: astroid.ClassDef, parent: astroid.ClassDef) -> bool:
return False
for ancestor in child.ancestors():
- if astroid.helpers.is_subtype(ancestor, parent):
- return True
+ try:
+ if astroid.helpers.is_subtype(ancestor, parent):
+ return True
+ except _NonDeducibleTypeHierarchy:
+ continue
return False