From 35b6ec7f90018bfafccd5d1918973f640637750f Mon Sep 17 00:00:00 2001 From: Torsten Marek Date: Fri, 22 Aug 2014 22:24:36 +0200 Subject: 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. --- scoped_nodes.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scoped_nodes.py b/scoped_nodes.py index 5f7f39b..eb60298 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 -- cgit v1.2.1