[pypy-svn] r76708 - in pypy/branch/rsre2/pypy/rpython: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Aug 24 13:31:24 CEST 2010
Author: arigo
Date: Tue Aug 24 13:31:23 2010
New Revision: 76708
Modified:
pypy/branch/rsre2/pypy/rpython/rclass.py
pypy/branch/rsre2/pypy/rpython/test/test_rclass.py
Log:
Test and fix for classes that have _immutable_fields_=[...]
but not their parent.
Modified: pypy/branch/rsre2/pypy/rpython/rclass.py
==============================================================================
--- pypy/branch/rsre2/pypy/rpython/rclass.py (original)
+++ pypy/branch/rsre2/pypy/rpython/rclass.py Tue Aug 24 13:31:23 2010
@@ -156,14 +156,13 @@
if '_immutable_' in self.classdef.classdesc.classdict:
hints = hints.copy()
hints['immutable'] = True
+ self.immutable_field_list = [] # unless overwritten below
if self.classdef.classdesc.lookup('_immutable_fields_') is not None:
hints = hints.copy()
immutable_fields = self.classdef.classdesc.classdict.get(
'_immutable_fields_')
if immutable_fields is not None:
self.immutable_field_list = immutable_fields.value
- else:
- self.immutable_field_list = []
accessor = FieldListAccessor()
hints['immutable_fields'] = accessor
return hints
Modified: pypy/branch/rsre2/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/branch/rsre2/pypy/rpython/test/test_rclass.py (original)
+++ pypy/branch/rsre2/pypy/rpython/test/test_rclass.py Tue Aug 24 13:31:23 2010
@@ -777,6 +777,25 @@
assert accessor.fields == {"inst_x" : "", "inst_y" : ""} or \
accessor.fields == {"ox" : "", "oy" : ""} # for ootype
+ def test_immutable_fields_only_in_subclass(self):
+ from pypy.jit.metainterp.typesystem import deref
+ class A(object):
+ def __init__(self, x):
+ self.x = x
+ class B(A):
+ _immutable_fields_ = ["y"]
+ def __init__(self, x, y):
+ A.__init__(self, x)
+ self.y = y
+
+ def f():
+ return B(3, 5)
+ t, typer, graph = self.gengraph(f, [])
+ B_TYPE = deref(graph.getreturnvar().concretetype)
+ accessor = B_TYPE._hints["immutable_fields"]
+ assert accessor.fields == {"inst_y" : ""} or \
+ accessor.fields == {"oy" : ""} # for ootype
+
def test_immutable_inheritance(self):
class I(object):
def __init__(self, v):
More information about the Pypy-commit
mailing list