Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r66255:ee2311d4ba26 Date: 2013-08-20 14:15 +0200 http://bitbucket.org/pypy/pypy/changeset/ee2311d4ba26/
Log: Test and fix: 'object' has an empty __init__ which we should not copy. diff --git a/pypy/interpreter/buffer.py b/pypy/interpreter/buffer.py --- a/pypy/interpreter/buffer.py +++ b/pypy/interpreter/buffer.py @@ -19,7 +19,7 @@ from pypy.interpreter.typedef import TypeDef from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.error import OperationError -from rpython.rlib.objectmodel import compute_hash +from rpython.rlib.objectmodel import compute_hash, import_from_mixin from rpython.rlib.rstring import StringBuilder @@ -272,8 +272,6 @@ # ____________________________________________________________ class SubBufferMixin(object): - _mixin_ = True - def __init__(self, buffer, offset, size): self.buffer = buffer self.offset = offset @@ -297,10 +295,11 @@ # out of bounds return self.buffer.getslice(self.offset + start, self.offset + stop, step, size) -class SubBuffer(SubBufferMixin, Buffer): - pass +class SubBuffer(Buffer): + import_from_mixin(SubBufferMixin) -class RWSubBuffer(SubBufferMixin, RWBuffer): +class RWSubBuffer(RWBuffer): + import_from_mixin(SubBufferMixin) def setitem(self, index, char): self.buffer.setitem(self.offset + index, char) diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py --- a/pypy/objspace/descroperation.py +++ b/pypy/objspace/descroperation.py @@ -121,7 +121,7 @@ greens=['w_type'], reds='auto') class DescrOperation(object): - _mixin_ = True + # This is meant to be a *mixin*. def is_data_descr(space, w_obj): return space.lookup(w_obj, '__set__') is not None diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py --- a/pypy/objspace/std/objspace.py +++ b/pypy/objspace/std/objspace.py @@ -10,7 +10,7 @@ from rpython.rlib.objectmodel import instantiate, specialize, is_annotation_constant from rpython.rlib.debug import make_sure_not_resized from rpython.rlib.rarithmetic import base_int, widen, is_valid_int -from rpython.rlib.objectmodel import we_are_translated +from rpython.rlib.objectmodel import we_are_translated, import_from_mixin from rpython.rlib import jit # Object imports @@ -37,9 +37,10 @@ from pypy.objspace.std.stringtype import wrapstr from pypy.objspace.std.unicodetype import wrapunicode -class StdObjSpace(ObjSpace, DescrOperation): +class StdObjSpace(ObjSpace): """The standard object space, implementing a general-purpose object library in Restricted Python.""" + import_from_mixin(DescrOperation) def initialize(self): "NOT_RPYTHON: only for initializing the space." diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py --- a/rpython/rlib/objectmodel.py +++ b/rpython/rlib/objectmodel.py @@ -737,6 +737,8 @@ """ flatten = {} for base in inspect.getmro(M): + if base is object: + continue for key, value in base.__dict__.items(): if key.startswith('__') and key.endswith('__'): if key not in special_methods: 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 @@ -612,3 +612,12 @@ import_from_mixin(M, special_methods=['__str__']) assert str(A()).startswith('<') assert str(B()) == "m!" + + class M(object): + pass + class A(object): + def __init__(self): + self.foo = 42 + class B(A): + import_from_mixin(M) + assert B().foo == 42 _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit