Esempio n. 1
0
    def igetattr(self, name, context=None):
        """inferred getattr"""
        if hasattr(self._proxied,
                   "attr_types") and name in self._proxied.attr_types:
            yield self._proxied.attr_types[name]
            return

        found = False

        try:
            # XXX frame should be self._proxied, or not ?
            get_attr = self.getattr(name, context, lookupclass=False)
            for inferred in bases._infer_stmts(self._wrap_attr(
                    get_attr, context),
                                               context,
                                               frame=self):
                yield inferred
            found = True
        except (NotFoundError, InferenceError):
            pass

        try:
            # fallback to class'igetattr since it has some logic to handle
            # descriptors
            for inferred in self._wrap_attr(
                    self._proxied.igetattr(name, context), context):
                yield inferred
            found = True
        except (NotFoundError, InferenceError):
            pass

        if not found:
            raise InferenceError(name)
Esempio n. 2
0
def infer_global(self, context=None):
    if context.lookupname is None:
        raise InferenceError()
    try:
        return _infer_stmts(self.root().getattr(context.lookupname), context)
    except NotFoundError:
        raise InferenceError()
Esempio n. 3
0
 def igetattr(self, name, context=None):
     """inferred getattr, need special treatment in class to handle
     descriptors
     """
     # set lookup name since this is necessary to infer on import nodes for
     # instance
     context = copy_context(context)
     context.lookupname = name
     try:
         for infered in _infer_stmts(self.getattr(name, context), context,
                                     frame=self):
             # yield YES object instead of descriptors when necessary
             if not isinstance(infered, Const) and isinstance(infered, Instance):
                 try:
                     infered._proxied.getattr('__get__', context)
                 except NotFoundError:
                     yield infered
                 else:
                     yield YES
             else:
                 yield function_to_method(infered, self)
     except NotFoundError:
         if not name.startswith('__') and self.has_dynamic_getattr(context):
             # class handle some dynamic attributes, return a YES object
             yield YES
         else:
             raise InferenceError(name)
Esempio n. 4
0
def infer_global(self, context=None):
    if context.lookupname is None:
        raise InferenceError()
    try:
        return _infer_stmts(self.root().getattr(context.lookupname), context)
    except NotFoundError:
        raise InferenceError()
Esempio n. 5
0
 def igetattr(self, name, context=None):
     """inferred getattr, need special treatment in class to handle
     descriptors
     """
     # set lookup name since this is necessary to infer on import nodes for
     # instance
     context = copy_context(context)
     context.lookupname = name
     try:
         for infered in _infer_stmts(self.getattr(name, context), context,
                                     frame=self):
             # yield YES object instead of descriptors when necessary
             if not isinstance(infered, Const) and isinstance(infered, Instance):
                 try:
                     infered._proxied.getattr('__get__', context)
                 except NotFoundError:
                     yield infered
                 else:
                     yield YES
             else:
                 yield function_to_method(infered, self)
     except NotFoundError:
         if not name.startswith('__') and self.has_dynamic_getattr(context):
             # class handle some dynamic attributes, return a YES object
             yield YES
         else:
             raise InferenceError(name)
Esempio n. 6
0
    def igetattr(self, name, context=None):
        """inferred getattr"""
        if hasattr(self._proxied, "attr_types") and name in self._proxied.attr_types:
            yield self._proxied.attr_types[name]
            return

        found = False

        try:
            # XXX frame should be self._proxied, or not ?
            get_attr = self.getattr(name, context, lookupclass=False)
            for inferred in bases._infer_stmts(self._wrap_attr(get_attr, context), context,frame=self):
                yield inferred
            found = True
        except (NotFoundError, InferenceError):
            pass

        try:
            # fallback to class'igetattr since it has some logic to handle
            # descriptors
            for inferred in  self._wrap_attr(self._proxied.igetattr(name, context),context):
                yield inferred
            found = True
        except (NotFoundError, InferenceError):
            pass

        if not found:
            raise InferenceError(name)
Esempio n. 7
0
def infer_name(self, context=None):
    """infer a Name: use name lookup rules"""
    frame, stmts = self.lookup(self.name)
    if not stmts:
        raise UnresolvableName(self.name)
    context = context.clone()
    context.lookupname = self.name
    return _infer_stmts(stmts, context, frame)
Esempio n. 8
0
def infer_name(self, context=None):
    """infer a Name: use name lookup rules"""
    frame, stmts = self.lookup(self.name)
    if not stmts:
        raise UnresolvableName(self.name)
    context = context.clone()
    context.lookupname = self.name
    return _infer_stmts(stmts, context, frame)
Esempio n. 9
0
    def ilookup(self, name):
        """infered lookup

        return an iterator on infered values of the statements returned by
        the lookup method
        """
        frame, stmts = self.lookup(name)
        context = InferenceContext()
        return _infer_stmts(stmts, context, frame)
Esempio n. 10
0
def infer_ass(self, context=None):
    """infer a AssName/AssAttr: need to inspect the RHS part of the
    assign node
    """
    stmt = self.statement()
    if isinstance(stmt, nodes.AugAssign):
        return stmt.infer(context)
    stmts = list(self.assigned_stmts(context=context))
    return _infer_stmts(stmts, context)
Esempio n. 11
0
def infer_ass(self, context=None):
    """infer a AssName/AssAttr: need to inspect the RHS part of the
    assign node
    """
    stmt = self.statement()
    if isinstance(stmt, nodes.AugAssign):
        return stmt.infer(context)
    stmts = list(self.assigned_stmts(context=context))
    return _infer_stmts(stmts, context)
Esempio n. 12
0
    def ilookup(self, name):
        """infered lookup

        return an iterator on infered values of the statements returned by
        the lookup method
        """
        frame, stmts = self.lookup(name)
        context = InferenceContext()
        return _infer_stmts(stmts, context, frame)
Esempio n. 13
0
 def igetattr(self, name, context=None):
     """inferred getattr"""
     # set lookup name since this is necessary to infer on import nodes for
     # instance
     context = copy_context(context)
     context.lookupname = name
     try:
         return _infer_stmts(self.getattr(name, context), context, frame=self)
     except NotFoundError:
         raise InferenceError(name)
Esempio n. 14
0
    def ilookup(self, name, context=None):
        """infered lookup

        return an iterator on infered values of the statements returned by
        the lookup method
        """
        frame, stmts = self.lookup(name)
        context = copy_context(context)
        context.lookupname = name
        return _infer_stmts(stmts, context, frame)
Esempio n. 15
0
 def igetattr(self, name, context=None):
     """inferred getattr"""
     # set lookup name since this is necessary to infer on import nodes for
     # instance
     context = copy_context(context)
     context.lookupname = name
     try:
         return _infer_stmts(self.getattr(name, context), context, frame=self)
     except NotFoundError:
         raise InferenceError(name)
Esempio n. 16
0
    def ilookup(self, name, context=None):
        """infered lookup

        return an iterator on infered values of the statements returned by
        the lookup method
        """
        frame, stmts = self.lookup(name)
        context = copy_context(context)
        context.lookupname = name
        return _infer_stmts(stmts, context, frame)
Esempio n. 17
0
 def infer_from(self, context=None, asname=True):
     name = context.lookupname
     if name is None:
         raise InferenceError()
     if asname:
         name = self.real_name(name)
     module = self.do_import_module(self.modname)
     try:
         context = copy_context(context)
         context.lookupname = name
         return _infer_stmts(module.getattr(name, ignore_locals=module is self.root()), context)
     except NotFoundError:
         raise InferenceError(name)
Esempio n. 18
0
def infer_from(self, context=None, asname=True):
    """infer a From nodes: return the imported module/object"""
    name = context.lookupname
    if name is None:
        raise InferenceError()
    if asname:
        name = self.real_name(name)
    module = self.do_import_module(self.modname)
    try:
        context = copy_context(context)
        context.lookupname = name
        return _infer_stmts(module.getattr(name), context)
    except NotFoundError:
        raise InferenceError(name)
Esempio n. 19
0
def infer_from(self, context=None, asname=True):
    """infer a From nodes: return the imported module/object"""
    name = context.lookupname
    if name is None:
        raise InferenceError()
    if asname:
        name = self.real_name(name)
    module = self.do_import_module(self.modname)
    try:
        context = copy_context(context)
        context.lookupname = name
        return _infer_stmts(module.getattr(name), context)
    except NotFoundError:
        raise InferenceError(name)
Esempio n. 20
0
 def infer_from(self, context=None, asname=True):
     name = context.lookupname
     if name is None:
         raise InferenceError()
     if asname:
         name = self.real_name(name)
     module = self.do_import_module(self.modname)
     try:
         context = copy_context(context)
         context.lookupname = name
         return _infer_stmts(
             module.getattr(name, ignore_locals=module is self.root()),
             context)
     except NotFoundError:
         raise InferenceError(name)