Author: Carl Friedrich Bolz <cfb...@gmx.de>
Branch: 
Changeset: r78892:dd5e385a1000
Date: 2015-08-11 15:23 +0200
http://bitbucket.org/pypy/pypy/changeset/dd5e385a1000/

Log:    (arigo, cfbolz): make import_from_mixin deal with _immutable_fields_

diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -806,10 +806,14 @@
     flatten = {}
     caller = sys._getframe(1)
     caller_name = caller.f_globals.get('__name__')
+    immutable_fields = []
     for base in inspect.getmro(M):
         if base is object:
             continue
         for key, value in base.__dict__.items():
+            if key == '_immutable_fields_':
+                immutable_fields.extend(value)
+                continue
             if key.startswith('__') and key.endswith('__'):
                 if key not in special_methods:
                     continue
@@ -836,3 +840,5 @@
             raise Exception("import_from_mixin: would overwrite the value "
                             "already defined locally for %r" % (key,))
         target[key] = value
+    if immutable_fields:
+        target['_immutable_fields_'] = target.get('_immutable_fields_', []) + 
immutable_fields
diff --git a/rpython/rlib/test/test_objectmodel.py 
b/rpython/rlib/test/test_objectmodel.py
--- a/rpython/rlib/test/test_objectmodel.py
+++ b/rpython/rlib/test/test_objectmodel.py
@@ -675,3 +675,44 @@
         import_from_mixin(M)
     assert A.f is not M.f
     assert A.f.__module__ != M.f.__module__
+
+
+def test_import_from_mixin_immutable_fields():
+    class A(object):
+        _immutable_fields_ = ['a']
+
+    class B(object):
+        _immutable_fields_ = ['b']
+        import_from_mixin(A)
+
+    assert B._immutable_fields_ == ['b', 'a']
+    assert A._immutable_fields_ == ['a']
+
+
+    class B(object):
+        import_from_mixin(A)
+
+    assert B._immutable_fields_ == ['a']
+
+    class C(A):
+        _immutable_fields_ = ['c']
+
+
+    class B(object):
+        import_from_mixin(C)
+
+    assert B._immutable_fields_ == ['c', 'a']
+
+    class B(object):
+        _immutable_fields_ = ['b']
+        import_from_mixin(C)
+
+    assert B._immutable_fields_ == ['b', 'c', 'a']
+
+
+    class B(object):
+        _immutable_fields_ = ['b']
+    class BA(B):
+        import_from_mixin(C)
+
+    assert BA._immutable_fields_ == ['c', 'a']
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to