示例#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
示例#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
示例#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
示例#4
0
def infer_name_module(node, name):
    context = InferenceContext(node)
    context.lookupname = name
    return node.infer(context, asname=False)
示例#5
0
def infer_name_module(node, name):
    context = InferenceContext(node)
    context.lookupname = name
    return node.infer(context, asname=False)