Exemplo n.º 1
0
 def set_metaclass(self):
     """Parse and set variables from metaclass
     """
     self.is_meta_end = True
     metas = []
     for meta in unpack_infer(self.metaclass):
         for base in meta.bases:
             for b in unpack_infer(base):
                 if b not in metas:
                     self.set_meta_object(b)
                     metas.append(b)
         if meta not in metas:
             self.set_meta_object(meta)
             metas.append(meta)
Exemplo n.º 2
0
    def test_bad_import_inference(self):
        # Explication of bug
        '''When we import PickleError from nonexistent, a call to the infer
        method of this From node will be made by unpack_infer.
        inference.infer_from will try to import this module, which will fail and
        raise a InferenceException (by mixins.do_import_module). The infer_name
        will catch this exception and yield and YES instead.
        '''

        code = '''try:
    from pickle import PickleError
except ImportError:
    from nonexistent import PickleError

try:
    pass
except PickleError:
    pass
        '''

        astng = abuilder.string_build(code)
        from_node = astng.body[1].handlers[0].body[0]
        handler_type = astng.body[1].handlers[0].type

        excs = list(unpack_infer(handler_type))
Exemplo n.º 3
0
    def test_bad_import_inference(self):
        # Explication of bug
        '''When we import PickleError from nonexistent, a call to the infer
        method of this From node will be made by unpack_infer.
        inference.infer_from will try to import this module, which will fail and
        raise a InferenceException (by mixins.do_import_module). The infer_name
        will catch this exception and yield and YES instead.
        '''

        code = '''try:
    from pickle import PickleError
except ImportError:
    from nonexistent import PickleError

try:
    pass
except PickleError:
    pass
        '''

        astng = abuilder.string_build(code)
        from_node = astng.body[1].handlers[0].body[0]
        handler_type = astng.body[1].handlers[0].type

        excs = list(unpack_infer(handler_type))
Exemplo n.º 4
0
 def interfaces(self, herited=True, handler_func=_iface_hdlr):
     """return an iterator on interfaces implemented by the given
     class node
     """
     # FIXME: what if __implements__ = (MyIFace, MyParent.__implements__)...
     try:
         implements = Instance(self).getattr('__implements__')[0]
     except NotFoundError:
         return
     if not herited and not implements.frame() is self:
         return
     found = set()
     for iface in unpack_infer(implements):
         if iface is YES:
             continue
         if not iface in found and handler_func(iface):
             found.add(iface)
             yield iface
     if not found:
         raise InferenceError()
Exemplo n.º 5
0
 def interfaces(self, herited=True, handler_func=_iface_hdlr):
     """return an iterator on interfaces implemented by the given
     class node
     """
     # FIXME: what if __implements__ = (MyIFace, MyParent.__implements__)...
     try:
         implements = Instance(self).getattr('__implements__')[0]
     except NotFoundError:
         return
     if not herited and not implements.frame() is self:
         return
     found = set()
     for iface in unpack_infer(implements):
         if iface is YES:
             continue
         if not iface in found and handler_func(iface):
             found.add(iface)
             yield iface
     if not found:
         raise InferenceError()
Exemplo n.º 6
0
def excepthandler_assigned_stmts(self, node, context=None, asspath=None):
    for assigned in unpack_infer(self.type):
        if isinstance(assigned, nodes.Class):
            assigned = Instance(assigned)
        yield assigned
Exemplo n.º 7
0
def excepthandler_assigned_stmts(self, node, context=None, asspath=None):
    for assigned in unpack_infer(self.type):
        if isinstance(assigned, nodes.Class):
            assigned = Instance(assigned)
        yield assigned