[pypy-svn] r11603 - in pypy/dist/pypy/module: builtin test

pedronis at codespeak.net pedronis at codespeak.net
Thu Apr 28 18:07:26 CEST 2005


Author: pedronis
Date: Thu Apr 28 18:07:25 2005
New Revision: 11603

Modified:
   pypy/dist/pypy/module/builtin/app_inspect.py
   pypy/dist/pypy/module/test/test_builtin.py
Log:
fixing callable for oldstyle instances



Modified: pypy/dist/pypy/module/builtin/app_inspect.py
==============================================================================
--- pypy/dist/pypy/module/builtin/app_inspect.py	(original)
+++ pypy/dist/pypy/module/builtin/app_inspect.py	Thu Apr 28 18:07:25 2005
@@ -74,8 +74,11 @@
         return False
 
 def callable(ob):
+    import __builtin__
     for c in type(ob).__mro__:
         if '__call__' in c.__dict__:
+            if isinstance(ob, __builtin__._instance): # old style instance!
+                return getattr(ob, '__call__', None) is not None
             return True
     else:
         return False

Modified: pypy/dist/pypy/module/test/test_builtin.py
==============================================================================
--- pypy/dist/pypy/module/test/test_builtin.py	(original)
+++ pypy/dist/pypy/module/test/test_builtin.py	Thu Apr 28 18:07:25 2005
@@ -289,10 +289,16 @@
         class Call:
             def __call__(self, a):
                 return a+2
-        assert not not callable(Call()), (
+        assert callable(Call()), (
                     "Builtin function 'callable' misreads callable object")
         assert callable(int), (
                     "Builtin function 'callable' misreads int")
+        class Call:
+            __metaclass__ = _classobj
+            def __call__(self, a):
+                return a+2
+        assert callable(Call())
+
 
     def test_uncallable(self):
         # XXX TODO: I made the NoCall class explicitly newstyle to try and
@@ -307,6 +313,9 @@
         a.__call__ = lambda: "foo"
         assert not callable(a), (
                     "Builtin function 'callable' tricked by instance-__call__")
+        class NoCall:
+            __metaclass__ = _classobj
+        assert not callable(NoCall())
 
     def test_hash(self):
         assert hash(23) == hash(23)



More information about the Pypy-commit mailing list