diff options
author | Torsten Marek <shlomme@gmail.com> | 2014-08-22 22:24:36 +0200 |
---|---|---|
committer | Torsten Marek <shlomme@gmail.com> | 2014-08-22 22:24:36 +0200 |
commit | 1eeeb23a1813b5836ca1c5e852785f7c5feddb1f (patch) | |
tree | a9b760aa7e1ec4b8505932c9b228e825b07bc054 /scoped_nodes.py | |
parent | 2721b8efd9e2a22824ffb71916038a97b03b1826 (diff) | |
download | astroid-git-1eeeb23a1813b5836ca1c5e852785f7c5feddb1f.tar.gz |
Guard against infinite recursion in _is_metaclass.
Unfortunately, I wasn't able to boil this down to a small-enough reproduction case, since
the case that I had depended on conditional imports.
Diffstat (limited to 'scoped_nodes.py')
-rw-r--r-- | scoped_nodes.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/scoped_nodes.py b/scoped_nodes.py index 5f7f39b9..eb60298f 100644 --- a/scoped_nodes.py +++ b/scoped_nodes.py @@ -756,15 +756,21 @@ def _rec_get_names(args, names=None): # Class ###################################################################### -def _is_metaclass(klass): +def _is_metaclass(klass, seen=None): """ Return if the given class can be used as a metaclass. """ if klass.name == 'type': return True + if seen is None: + seen = set() for base in klass.bases: try: for baseobj in base.infer(): + if baseobj in seen: + continue + else: + seen.add(baseobj) if isinstance(baseobj, Instance): # not abstract return False @@ -776,7 +782,7 @@ def _is_metaclass(klass): continue if baseobj._type == 'metaclass': return True - if _is_metaclass(baseobj): + if _is_metaclass(baseobj, seen): return True except InferenceError: continue |