[pypy-svn] r10018 - in pypy/dist/pypy/objspace: . test
arigo at codespeak.net
arigo at codespeak.net
Mon Mar 21 21:13:42 CET 2005
Author: arigo
Date: Mon Mar 21 21:13:42 2005
New Revision: 10018
Added:
pypy/dist/pypy/objspace/test/test_idhackobjspace.py (contents, props changed)
Modified:
pypy/dist/pypy/objspace/idhack.py
Log:
Saner semantics for id() in the presence of become().
Modified: pypy/dist/pypy/objspace/idhack.py
==============================================================================
--- pypy/dist/pypy/objspace/idhack.py (original)
+++ pypy/dist/pypy/objspace/idhack.py Mon Mar 21 21:13:42 2005
@@ -22,8 +22,7 @@
try:
return w_obj.__id
except AttributeError:
- w_obj.__id = id(w_obj)
- return w_obj.__id
+ return id(w_obj)
class IdHackSpace(std.Space):
@@ -49,5 +48,6 @@
def become(space, w_target, w_source):
w_target.__class__ = w_source.__class__
w_target.__dict__ = w_source.__dict__
+ w_target.__id = idhack(w_source)
return space.w_None
app_become = gateway.interp2app(become)
Added: pypy/dist/pypy/objspace/test/test_idhackobjspace.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/objspace/test/test_idhackobjspace.py Mon Mar 21 21:13:42 2005
@@ -0,0 +1,19 @@
+
+class AppTest_IdHack:
+
+ objspacename = 'idhack'
+
+ def test_simple(self):
+ x = 5
+ y = 6
+ assert x is not y
+ become(x, y)
+ assert x is y
+
+ def test_id(self):
+ # these are the Smalltalk semantics of become().
+ x = 5; idx = id(x)
+ y = 6; idy = id(y)
+ assert idx != idy
+ become(x, y)
+ assert id(x) == id(y) == idy
More information about the Pypy-commit
mailing list