[pypy-commit] pypy SomeRange: Make range() lists immutable

rlamy pypy.commits at gmail.com
Sat Jan 30 13:42:40 EST 2016


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: SomeRange
Changeset: r82009:3b3f8cea104f
Date: 2016-01-30 18:16 +0000
http://bitbucket.org/pypy/pypy/changeset/3b3f8cea104f/

Log:	Make range() lists immutable

diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -9,7 +9,7 @@
     SomeDict, SomeUnicodeCodePoint, SomeUnicodeString, SomeException,
     SomeTuple, SomeImpossibleValue, s_ImpossibleValue, SomeInstance,
     SomeBuiltinMethod, SomeIterator, SomePBC, SomeNone, SomeFloat, s_None,
-    SomeByteArray, SomeWeakRef, SomeSingleFloat,
+    SomeByteArray, SomeWeakRef, SomeSingleFloat, SomeRange,
     SomeLongFloat, SomeType, SomeTypeOf, SomeConstantType, unionof, UnionError,
     read_can_only_throw, add_knowntypedata,
     merge_knowntypedata,)
@@ -486,6 +486,12 @@
         return lst1
     inplace_mul.can_only_throw = []
 
+class __extend__(pairtype(SomeRange, SomeObject)):
+
+    def inplace_mul((lst1, obj2)):
+        raise AnnotatorError(
+            "In RPython, lists returned by range() are immutable")
+
 class __extend__(pairtype(SomeTuple, SomeTuple)):
 
     def union((tup1, tup2)):
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -14,7 +14,7 @@
     SomeUnicodeCodePoint, SomeInstance, SomeBuiltin, SomeBuiltinMethod,
     SomeFloat, SomeIterator, SomePBC, SomeNone, SomeTypeOf, s_ImpossibleValue,
     s_Bool, s_None, s_Int, unionof, add_knowntypedata,
-    SomeWeakRef, SomeUnicodeString, SomeByteArray)
+    SomeWeakRef, SomeUnicodeString, SomeByteArray, SomeRange)
 from rpython.annotator.bookkeeper import getbookkeeper, immutablevalue
 from rpython.annotator.binaryop import _clone ## XXX where to put this?
 from rpython.annotator.binaryop import _dict_can_only_throw_keyerror
@@ -429,6 +429,32 @@
         check_negative_slice(s_start, s_stop)
         self.listdef.resize()
 
+class __extend__(SomeRange):
+
+    def method_append(self, s_value):
+        raise AnnotatorError(
+            "In RPython, lists returned by range() are immutable")
+
+    def method_extend(self, s_iterable):
+        raise AnnotatorError(
+            "In RPython, lists returned by range() are immutable")
+
+    def method_reverse(self):
+        raise AnnotatorError(
+            "In RPython, lists returned by range() are immutable")
+
+    def method_insert(self, s_index, s_value):
+        raise AnnotatorError(
+            "In RPython, lists returned by range() are immutable")
+
+    def method_remove(self, s_value):
+        raise AnnotatorError(
+            "In RPython, lists returned by range() are immutable")
+
+    def method_pop(self, s_index=None):
+        raise AnnotatorError(
+            "In RPython, lists returned by range() are immutable")
+
 def check_negative_slice(s_start, s_stop, error="slicing"):
     if isinstance(s_start, SomeInteger) and not s_start.nonneg:
         raise AnnotatorError("%s: not proven to have non-negative start" %


More information about the pypy-commit mailing list