Author: Armin Rigo <[email protected]>
Branch:
Changeset: r69574:492582e28528
Date: 2014-03-01 18:39 +0100
http://bitbucket.org/pypy/pypy/changeset/492582e28528/
Log: Crash early when trying to assign a resizable list into a 'lst[*]'
attribute.
diff --git a/rpython/annotator/test/test_annrpython.py
b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -3722,6 +3722,18 @@
a = self.RPythonAnnotator()
py.test.raises(ListChangeUnallowed, a.build_types, f, [int])
+ def test_immutable_list_is_assigned_a_resizable_list(self):
+ class A:
+ _immutable_fields_ = 'lst[*]'
+ def f(n):
+ a = A()
+ foo = []
+ foo.append(n)
+ a.lst = foo
+
+ a = self.RPythonAnnotator()
+ py.test.raises(ListChangeUnallowed, a.build_types, f, [int])
+
def test_can_merge_immutable_list_with_regular_list(self):
class A:
_immutable_fields_ = 'lst[*]'
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -676,6 +676,12 @@
# create or update the attribute in clsdef
clsdef.generalize_attr(attr, s_value)
+ if isinstance(s_value, SomeList):
+ clsdef.classdesc.maybe_return_immutable_list(
+ attr, s_value)
+ else:
+ raise AnnotatorError("setattr(instance, variable_attr, value)")
+
def bool_behavior(self, s):
if not self.can_be_None:
s.const = True
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit