[pypy-commit] pypy default: complain when handed an old-style instance

gutworth noreply at buildbot.pypy.org
Tue May 24 00:54:31 CEST 2011


Author: Benjamin Peterson <benjamin at python.org>
Branch: 
Changeset: r44391:31c8db410145
Date: 2011-05-23 18:01 -0500
http://bitbucket.org/pypy/pypy/changeset/31c8db410145/

Log:	complain when handed an old-style instance

diff --git a/pypy/module/__pypy__/interp_magic.py b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -1,4 +1,5 @@
 from pypy.interpreter.baseobjspace import ObjSpace, W_Root
+from pypy.interpreter.error import OperationError
 from pypy.interpreter.gateway import unwrap_spec
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.objspace.std.typeobject import MethodCache
@@ -62,6 +63,9 @@
 @unwrap_spec(ObjSpace, W_Root, str)
 def lookup_special(space, w_obj, meth):
     """Lookup up a special method on an object."""
+    if space.is_oldstyle_instance(w_obj):
+        w_msg = space.wrap("this doesn't do what you want on old-style classes")
+        raise OperationError(space.w_TypeError, w_msg)
     w_descr = space.lookup(w_obj, meth)
     if w_descr is None:
         return space.w_None
diff --git a/pypy/module/__pypy__/test/test_special.py b/pypy/module/__pypy__/test/test_special.py
--- a/pypy/module/__pypy__/test/test_special.py
+++ b/pypy/module/__pypy__/test/test_special.py
@@ -44,3 +44,6 @@
         x = X()
         x.foo = 23
         assert lookup_special(x, "foo")() == 42
+        class X:
+            pass
+        raises(TypeError, lookup_special, X(), "foo")


More information about the pypy-commit mailing list