Ejemplo n.º 1
0
 def ancestors(self, recurs=True, context=None):
     """return an iterator on the node base classes in a prefixed
     depth first order
     
     :param recurs:
       boolean indicating if it should recurse or return direct
       ancestors only
     """
     # FIXME: should be possible to choose the resolution order
     # XXX inference make infinite loops possible here (see BaseTransformer
     # manipulation in the builder module for instance !)
     context = context or InferenceContext()
     for stmt in self.bases:
         try:
             for baseobj in stmt.infer(context):
                 if not isinstance(baseobj, Class):
                     # duh ?
                     continue
                 if baseobj is self:
                     continue  # cf xxx above
                 yield baseobj
                 if recurs:
                     for grandpa in baseobj.ancestors(True, context):
                         if grandpa is self:
                             continue  # cf xxx above
                         yield grandpa
         except InferenceError:
             #import traceback
             #traceback.print_exc()
             # XXX log error ?
             continue
Ejemplo n.º 2
0
 def _newstyle_impl(self, context=None):
     context = context or InferenceContext()
     if self._newstyle is not None:
         return self._newstyle
     for base in self.ancestors(recurs=False, context=context):
         if base._newstyle_impl(context):
             self._newstyle = True
             break
     if self._newstyle is None:
         self._newstyle = False
     return self._newstyle
Ejemplo n.º 3
0
 def wrapped(node, context=None, _func=func, **kwargs):
     """wrapper function handling context"""
     if context is None:
         context = InferenceContext(node)
     context.push(node)
     yielded = set()
     try:
         for res in _func(node, context, **kwargs):
             # unproxy only true instance, not const, tuple, dict...
             if res.__class__ is Instance:
                 ares = res._proxied
             else:
                 ares = res
             if not ares in yielded:
                 yield res
                 yielded.add(ares)
         context.pop()
     except:
         context.pop()
         raise
Ejemplo n.º 4
0
def infer_name_module(node, name):
    context = InferenceContext(node)
    context.lookupname = name
    return node.infer(context, asname=False)
Ejemplo n.º 5
0
def infer_name_module(node, name):
    context = InferenceContext(node)
    context.lookupname = name
    return node.infer(context, asname=False)