[pypy-commit] pypy py3k: CPython issue #1721812: Binary operations and copy operations on

amauryfa noreply at buildbot.pypy.org
Sat Jan 14 21:48:33 CET 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r51323:3924c71a5c0a
Date: 2011-12-26 17:49 +0100
http://bitbucket.org/pypy/pypy/changeset/3924c71a5c0a/

Log:	CPython issue #1721812: Binary operations and copy operations on
	set/frozenset subclasses need to return the base type, not the
	subclass itself.

diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -44,12 +44,7 @@
 
     def _newobj(w_self, space, rdict_w):
         """Make a new set by taking ownership of 'rdict_w'."""
-        if type(w_self) is W_SetObject:
-            return W_SetObject(space, rdict_w)
-        w_type = space.type(w_self)
-        w_obj = space.allocate_instance(W_SetObject, w_type)
-        W_SetObject.__init__(w_obj, space, rdict_w)
-        return w_obj
+        return W_SetObject(space, rdict_w)
 
 class W_FrozensetObject(W_BaseSetObject):
     from pypy.objspace.std.frozensettype import frozenset_typedef as typedef
@@ -57,12 +52,7 @@
 
     def _newobj(w_self, space, rdict_w):
         """Make a new frozenset by taking ownership of 'rdict_w'."""
-        if type(w_self) is W_FrozensetObject:
-            return W_FrozensetObject(space, rdict_w)
-        w_type = space.type(w_self)
-        w_obj = space.allocate_instance(W_FrozensetObject, w_type)
-        W_FrozensetObject.__init__(w_obj, space, rdict_w)
-        return w_obj
+        return W_FrozensetObject(space, rdict_w)
 
 registerimplementation(W_BaseSetObject)
 registerimplementation(W_SetObject)
diff --git a/pypy/objspace/std/test/test_setobject.py b/pypy/objspace/std/test/test_setobject.py
--- a/pypy/objspace/std/test/test_setobject.py
+++ b/pypy/objspace/std/test/test_setobject.py
@@ -59,7 +59,7 @@
         class subset(set):pass
         a = subset()
         b = a | set('abc')
-        assert type(b) is subset
+        assert type(b) is set
 
     def test_init_new_behavior(self):
         s = set.__new__(set, 'abc')
@@ -77,14 +77,14 @@
         b = subset('abc')
         subset.__new__ = lambda *args: foobar   # not called
         b = b.copy()
-        assert type(b) is subset
+        assert type(b) is set
         assert set(b) == set('abc')
         #
         class frozensubset(frozenset): pass
         b = frozensubset('abc')
         frozensubset.__new__ = lambda *args: foobar   # not called
         b = b.copy()
-        assert type(b) is frozensubset
+        assert type(b) is frozenset
         assert frozenset(b) == frozenset('abc')
 
     def test_union(self):
@@ -160,7 +160,7 @@
         s2 = s1.copy()
         assert s1 is not s2
         assert s1 == s2
-        assert type(s2) is myfrozen
+        assert type(s2) is frozenset
 
     def test_update(self):
         s1 = set('abc')
@@ -317,8 +317,7 @@
             s = subset([2])
             assert s.x == ([2],)
             t = s | base([5])
-            # obscure CPython behavior:
-            assert type(t) is subset
+            assert type(t) is base
             assert not hasattr(t, 'x')
 
     def test_isdisjoint(self):


More information about the pypy-commit mailing list