Author: Armin Rigo <[email protected]>
Branch:
Changeset: r61860:62b9efd10322
Date: 2013-02-26 14:48 +0100
http://bitbucket.org/pypy/pypy/changeset/62b9efd10322/
Log: Complain loudly if we attempt to mutate an lltype which has a cached
hash already.
diff --git a/rpython/rtyper/lltypesystem/lltype.py
b/rpython/rtyper/lltypesystem/lltype.py
--- a/rpython/rtyper/lltypesystem/lltype.py
+++ b/rpython/rtyper/lltypesystem/lltype.py
@@ -105,6 +105,23 @@
_is_compatible = __eq__
+ def __setattr__(self, attr, nvalue):
+ try:
+ LowLevelType.__cached_hash.__get__(self)
+ except AttributeError:
+ pass
+ else:
+ try:
+ reprself = repr(self)
+ except:
+ try:
+ reprself = str(self)
+ except:
+ reprself = object.__repr__(self)
+ raise AssertionError("%s: changing the field %r but we already "
+ "computed the hash" % (reprself, attr))
+ object.__setattr__(self, attr, nvalue)
+
def _enforce(self, value):
if typeOf(value) != self:
raise TypeError
@@ -486,6 +503,10 @@
return obj
def __init__(self, OF, length, **kwds):
+ if hasattr(self, '_name'):
+ assert self.OF == OF
+ assert self.length == length
+ return
fields = [('item%d' % i, OF) for i in range(length)]
super(FixedSizeArray, self).__init__('array%d' % length, *fields,
**kwds)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit