[pypy-commit] lang-io default: fix Object getSlot to not only look in the own slots but do a full lookup

bivab noreply at buildbot.pypy.org
Fri Sep 23 09:48:40 CEST 2011


Author: David Schneider <david.schneider at picle.org>
Branch: 
Changeset: r47:912b15c364e0
Date: 2011-09-23 09:47 +0200
http://bitbucket.org/pypy/lang-io/changeset/912b15c364e0/

Log:	fix Object getSlot to not only look in the own slots but do a full
	lookup

diff --git a/io/object.py b/io/object.py
--- a/io/object.py
+++ b/io/object.py
@@ -14,10 +14,10 @@
 
 @register_method('Object', 'getSlot', unwrap_spec=[object, str])
 def w_object_get_slot(space, w_target, name):
-    try:
-        return w_target.slots[name]
-    except KeyError:
-        return space.w_nil
+    w_value = w_target.lookup(name)
+    if w_value:
+        return w_value
+    return space.w_nil
 
 @register_method('Object', 'hasSlot', unwrap_spec=[object, str])
 def w_object_has_slot(space, w_target, name):
diff --git a/io/test/test_object.py b/io/test/test_object.py
--- a/io/test/test_object.py
+++ b/io/test/test_object.py
@@ -32,6 +32,20 @@
     res, space = interpret(inp)
     assert res.value == 'foo'
 
+def test_object_get_proto_slot():
+    inp = """
+    a := Object clone
+    a someValue := 123
+    b := a clone
+    b getSlot("someValue")"""
+    res, space = interpret(inp)
+    assert res.number_value == 123
+
+def test_object_get_slot_fail():
+    inp = 'Object getSlot("notHere")'
+    res, space = interpret(inp)
+    assert res is space.w_nil
+
 def test_object_has_slot():
     inp = 'Object hasSlot("foo")'
     res, space = interpret(inp)


More information about the pypy-commit mailing list