Пример #1
0
def std_special_attributes(self, name, add_locals=True):
    if add_locals:
        locals = self.locals
    else:
        locals = {}
    if name == '__name__':
        return [cf(self.name)] + locals.get(name, [])
    if name == '__doc__':
        return [cf(self.doc)] + locals.get(name, [])
    if name == '__dict__':
        return [Dict()] + locals.get(name, [])
    raise NotFoundError(name)
Пример #2
0
def std_special_attributes(self, name, add_locals=True):
    if add_locals:
        locals = self.locals
    else:
        locals = {}
    if name == "__name__":
        return [cf(self.name)] + locals.get(name, [])
    if name == "__doc__":
        return [cf(self.doc)] + locals.get(name, [])
    if name == "__dict__":
        return [Dict()] + locals.get(name, [])
    raise NotFoundError(name)
Пример #3
0
    def getattr(self, name, context=None):
        """this method doesn't look in the instance_attrs dictionary since it's
        done by an Instance proxy at inference time.

        It may return a YES object if the attribute has not been actually
        found but a __getattr__ or __getattribute__ method is defined
        """
        values = self.locals.get(name, [])
        if name in self.special_attributes:
            if name == "__module__":
                return [cf(self.root().qname())] + values
            # FIXME: do we really need the actual list of ancestors?
            # returning [Tuple()] + values don't break any test
            # this is ticket http://www.logilab.org/ticket/52785
            # XXX need proper meta class handling + MRO implementation
            if name == "__bases__" or (name == "__mro__" and self.newstyle):
                node = Tuple()
                node.items = self.ancestors(recurs=True, context=context)
                return [node] + values
            return std_special_attributes(self, name)
        # don't modify the list in self.locals!
        values = list(values)
        for classnode in self.ancestors(recurs=True, context=context):
            values += classnode.locals.get(name, [])
        if not values:
            raise NotFoundError(name)
        return values
Пример #4
0
    def getattr(self, name, context=None):
        """this method doesn't look in the instance_attrs dictionary since it's
        done by an Instance proxy at inference time.

        It may return a YES object if the attribute has not been actually
        found but a __getattr__ or __getattribute__ method is defined
        """
        values = self.locals.get(name, [])
        if name in self.special_attributes:
            if name == '__module__':
                return [cf(self.root().qname())] + values
            # FIXME: do we really need the actual list of ancestors?
            # returning [Tuple()] + values don't break any test
            # this is ticket http://www.logilab.org/ticket/52785
            # XXX need proper meta class handling + MRO implementation
            if name == '__bases__' or (name == '__mro__' and self.newstyle):
                node = Tuple()
                node.items = self.ancestors(recurs=True, context=context)
                return [node] + values
            return std_special_attributes(self, name)
        # don't modify the list in self.locals!
        values = list(values)
        for classnode in self.ancestors(recurs=True, context=context):
            values += classnode.locals.get(name, [])
        if not values:
            raise NotFoundError(name)
        return values
Пример #5
0
 def getattr(self, name, context=None):
     """this method doesn't look in the instance_attrs dictionary since it's
     done by an Instance proxy at inference time.
     """
     if name == "__module__":
         return [cf(self.root().qname())]
     if name in self.instance_attrs:
         return self.instance_attrs[name]
     return std_special_attributes(self, name, False)
Пример #6
0
 def getattr(self, name, context=None):
     """this method doesn't look in the instance_attrs dictionary since it's
     done by an Instance proxy at inference time.
     """
     if name == '__module__':
         return [cf(self.root().qname())]
     if name in self.instance_attrs:
         return self.instance_attrs[name]
     return std_special_attributes(self, name, False)
Пример #7
0
 def getattr(self, name, context=None, ignore_locals=False):
     if name in self.special_attributes:
         if name == '__file__':
             return [cf(self.file)] + self.locals.get(name, [])
         if name == '__path__' and self.package:
             return [List()] + self.locals.get(name, [])
         return std_special_attributes(self, name)
     if not ignore_locals and name in self.locals:
         return self.locals[name]
     if self.package:
         try:
             return [self.import_module(name, relative_only=True)]
         except AstroidBuildingException:
             raise NotFoundError(name)
         except Exception:# XXX pylint tests never pass here; do we need it?
             import traceback
             traceback.print_exc()
     raise NotFoundError(name)
Пример #8
0
 def getattr(self, name, context=None, ignore_locals=False):
     if name in self.special_attributes:
         if name == '__file__':
             return [cf(self.file)] + self.locals.get(name, [])
         if name == '__path__' and self.package:
             return [List()] + self.locals.get(name, [])
         return std_special_attributes(self, name)
     if not ignore_locals and name in self.locals:
         return self.locals[name]
     if self.package:
         try:
             return [self.import_module(name, relative_only=True)]
         except AstroidBuildingException:
             raise NotFoundError(name)
         except Exception:# XXX pylint tests never pass here; do we need it?
             import traceback
             traceback.print_exc()
     raise NotFoundError(name)