Example #1
0
 def method_join(self, s_list):
     if s_None.contains(s_list):
         return SomeImpossibleValue()
     s_item = s_list.listdef.read_item()
     if s_None.contains(s_item):
         if isinstance(self, SomeUnicodeString):
             return immutablevalue(u"")
         return immutablevalue("")
     no_nul = self.no_nul and s_item.no_nul
     return self.basestringclass(no_nul=no_nul)
Example #2
0
 def method_join(self, s_list):
     if s_None.contains(s_list):
         return SomeImpossibleValue()
     s_item = s_list.listdef.read_item()
     if s_None.contains(s_item):
         if isinstance(self, SomeUnicodeString):
             return immutablevalue(u"")
         return immutablevalue("")
     no_nul = self.no_nul and s_item.no_nul
     return self.basestringclass(no_nul=no_nul)
Example #3
0
 def method_join(str, s_list):
     if s_None.contains(s_list):
         return SomeImpossibleValue()
     getbookkeeper().count("str_join", str)
     s_item = s_list.listdef.read_item()
     if s_None.contains(s_item):
         if isinstance(str, SomeUnicodeString):
             return immutablevalue(u"")
         return immutablevalue("")
     no_nul = str.no_nul and s_item.no_nul
     return str.basestringclass(no_nul=no_nul)
Example #4
0
    def _init_classdef(self):
        classdef = ClassDef(self.bookkeeper, self)
        self.bookkeeper.classdefs.append(classdef)
        self.classdef = classdef

        # forced attributes
        cls = self.pyobj
        if cls in FORCE_ATTRIBUTES_INTO_CLASSES:
            for name, s_value in FORCE_ATTRIBUTES_INTO_CLASSES[cls].items():
                classdef.generalize_attr(name, s_value)
                classdef.find_attribute(name).modified(classdef)

        # register all class attributes as coming from this ClassDesc
        # (as opposed to prebuilt instances)
        classsources = {}
        for attr in self.classdict:
            classsources[attr] = self    # comes from this ClassDesc
        classdef.setup(classsources)
        # look for a __del__ method and annotate it if it's there
        if '__del__' in self.classdict:
            from rpython.annotator.model import s_None, SomeInstance
            s_func = self.s_read_attribute('__del__')
            args_s = [SomeInstance(classdef)]
            s = self.bookkeeper.emulate_pbc_call(classdef, s_func, args_s)
            assert s_None.contains(s)
        return classdef
Example #5
0
    def getclassdef(self, key):
        try:
            return self._classdefs[key]
        except KeyError:
            from rpython.annotator.classdef import (
                ClassDef, FORCE_ATTRIBUTES_INTO_CLASSES)
            classdef = ClassDef(self.bookkeeper, self)
            self.bookkeeper.classdefs.append(classdef)
            self._classdefs[key] = classdef

            # forced attributes
            cls = self.pyobj
            if cls in FORCE_ATTRIBUTES_INTO_CLASSES:
                for name, s_value in FORCE_ATTRIBUTES_INTO_CLASSES[cls].items(
                ):
                    classdef.generalize_attr(name, s_value)
                    classdef.find_attribute(name).modified(classdef)

            # register all class attributes as coming from this ClassDesc
            # (as opposed to prebuilt instances)
            classsources = {}
            for attr in self.classdict:
                classsources[attr] = self  # comes from this ClassDesc
            classdef.setup(classsources)
            # look for a __del__ method and annotate it if it's there
            if '__del__' in self.classdict:
                from rpython.annotator.model import s_None, SomeInstance
                s_func = self.s_read_attribute('__del__')
                args_s = [SomeInstance(classdef)]
                s = self.bookkeeper.emulate_pbc_call(classdef, s_func, args_s)
                assert s_None.contains(s)
            return classdef
Example #6
0
 def next(self):
     if s_None.contains(self.s_container):
         return s_ImpossibleValue     # so far
     if self.variant == ("enumerate",):
         s_item = self.s_container.getanyitem()
         return SomeTuple((SomeInteger(nonneg=True), s_item))
     variant = self.variant
     if variant == ("reversed",):
         variant = ()
     return self.s_container.getanyitem(*variant)
Example #7
0
 def next(self):
     if s_None.contains(self.s_container):
         return s_ImpossibleValue  # so far
     if self.variant == ("enumerate", ):
         s_item = self.s_container.getanyitem()
         return SomeTuple((SomeInteger(nonneg=True), s_item))
     variant = self.variant
     if variant == ("reversed", ):
         variant = ()
     return self.s_container.getanyitem(*variant)
Example #8
0
 def compute_result_annotation(self, s_obj):
     if s_None.contains(s_obj):
         return s_obj
     assert isinstance(s_obj, (SomeString, SomeUnicodeString))
     if s_obj.no_nul:
         return s_obj
     new_s_obj = SomeObject.__new__(s_obj.__class__)
     new_s_obj.__dict__ = s_obj.__dict__.copy()
     new_s_obj.no_nul = True
     return new_s_obj
Example #9
0
 def compute_result_annotation(self, s_obj):
     if s_None.contains(s_obj):
         return s_obj
     assert isinstance(s_obj, (SomeString, SomeUnicodeString))
     if s_obj.no_nul:
         return s_obj
     new_s_obj = SomeObject.__new__(s_obj.__class__)
     new_s_obj.__dict__ = s_obj.__dict__.copy()
     new_s_obj.no_nul = True
     return new_s_obj
Example #10
0
File: unaryop.py Project: Mu-L/pypy
 def next(self):
     position = getbookkeeper().position_key
     if s_None.contains(self.s_container):
         return s_ImpossibleValue     # so far
     if self.variant and self.variant[0] == "enumerate":
         s_item = self.s_container.getanyitem(position)
         return SomeTuple((SomeInteger(nonneg=True), s_item))
     variant = self.variant
     if variant == ("reversed",):
         variant = ()
     return self.s_container.getanyitem(position, *variant)
Example #11
0
    def compute_result_annotation(self, s_arg):
        from rpython.annotator.model import SomeList, s_None
        from rpython.annotator.model import SomeChar, SomeUnicodeCodePoint
        from rpython.annotator.model import SomeImpossibleValue

        if s_None.contains(s_arg):
            return s_arg  # only None: just return
        assert isinstance(s_arg, SomeList)
        if not isinstance(s_arg.listdef.listitem.s_value, (SomeChar, SomeUnicodeCodePoint, SomeImpossibleValue)):
            raise NotAListOfChars
        return s_arg
Example #12
0
 def compute_result_annotation(self, s_arg):
     from rpython.annotator.model import SomeList, s_None
     from rpython.annotator.model import SomeChar, SomeUnicodeCodePoint
     from rpython.annotator.model import SomeImpossibleValue
     if s_None.contains(s_arg):
         return s_arg  # only None: just return
     assert isinstance(s_arg, SomeList)
     if not isinstance(
             s_arg.listdef.listitem.s_value,
         (SomeChar, SomeUnicodeCodePoint, SomeImpossibleValue)):
         raise NotAListOfChars
     return s_arg
Example #13
0
 def compute_result_annotation(self, s_arg):
     from rpython.annotator.model import SomeList, s_None
     if s_None.contains(s_arg):
         return s_arg    # only None: just return
     assert isinstance(s_arg, SomeList)
     # the logic behind it is that we try not to propagate
     # make_sure_not_resized, when list comprehension is not on
     if self.bookkeeper.annotator.translator.config.translation.list_comprehension_operations:
         s_arg.listdef.never_resize()
     else:
         from rpython.annotator.annrpython import log
         log.WARNING('make_sure_not_resized called, but has no effect since list_comprehension is off')
     return s_arg
Example #14
0
 def compute_result_annotation(self, s_arg):
     from rpython.annotator.model import SomeList, s_None
     if s_None.contains(s_arg):
         return s_arg  # only None: just return
     assert isinstance(s_arg, SomeList)
     # the logic behind it is that we try not to propagate
     # make_sure_not_resized, when list comprehension is not on
     if self.bookkeeper.annotator.translator.config.translation.list_comprehension_operations:
         s_arg.listdef.never_resize()
     else:
         from rpython.annotator.annrpython import log
         log.WARNING(
             'make_sure_not_resized called, but has no effect since list_comprehension is off'
         )
     return s_arg
Example #15
0
 def method_update(dct1, dct2):
     if s_None.contains(dct2):
         return SomeImpossibleValue()
     dct1.dictdef.union(dct2.dictdef)
Example #16
0
 def method_update(dct1, dct2):
     if s_None.contains(dct2):
         return SomeImpossibleValue()
     dct1.dictdef.union(dct2.dictdef)