Index: Lib/inspect.py =================================================================== --- Lib/inspect.py (revision 6666) +++ Lib/inspect.py (working copy) @@ -7,7 +7,7 @@ Here are some of the useful functions provided by this module: - ismodule(), isclass(), ismethod(), isfunction(), istraceback(), + ismodule(), isclass(), ismethod(), isreflectedfunction, isfunction(), istraceback(), isframe(), iscode(), isbuiltin(), isroutine() - check object types getmembers() - get members of an object that satisfy a given condition @@ -30,6 +30,7 @@ import sys, os, types, string, re, dis, imp, tokenize, linecache from operator import attrgetter +from org.python.core import PyReflectedFunction # ----------------------------------------------------------- type-checking def ismodule(object): @@ -191,12 +192,17 @@ __self__ instance to which a method is bound, or None""" return isinstance(object, types.BuiltinFunctionType) +def isreflectedfunction(object): + """Return true if the object is a reflected function""" + return isinstance(object, PyReflectedFunction) + def isroutine(object): """Return true if the object is any kind of function or method.""" return (isbuiltin(object) or isfunction(object) or ismethod(object) - or ismethoddescriptor(object)) + or ismethoddescriptor(object) + or isreflectedfunction(object)) def getmembers(object, predicate=None): """Return all members of an object as (name, value) pairs sorted by name. Index: Lib/test/test_inspect.py =================================================================== --- Lib/test/test_inspect.py (revision 6666) +++ Lib/test/test_inspect.py (working copy) @@ -4,6 +4,8 @@ import inspect import datetime +from java.lang import String + from test.test_support import TESTFN, run_unittest, is_jython from test import inspect_fodder as mod @@ -12,7 +14,7 @@ # Functions tested in this suite: # ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode, -# isbuiltin, isroutine, getmembers, getdoc, getfile, getmodule, +# isbuiltin, isreflectedfunction, isroutine, getmembers, getdoc, getfile, getmodule, # getsourcefile, getcomments, getsource, getclasstree, getargspec, # getargvalues, formatargspec, formatargvalues, currentframe, stack, trace # isdatadescriptor @@ -57,7 +59,8 @@ def test_thirteen(self): count = len(filter(lambda x:x.startswith('is'), dir(inspect))) # Doc/lib/libinspect.tex claims there are 13 such functions - expected = 13 + # true but I added one - isreflectedfunction + expected = 14 err_msg = "There are %d (not %d) is* functions" % (count, expected) self.assertEqual(count, expected, err_msg) @@ -70,6 +73,7 @@ self.istest(inspect.isclass, 'mod.StupidGit') self.istest(inspect.iscode, 'mod.spam.func_code') self.istest(inspect.isframe, 'tb.tb_frame') + self.istest(inspect.isreflectedfunction,'String.toUpperCase') self.istest(inspect.isfunction, 'mod.spam') self.istest(inspect.ismethod, 'mod.StupidGit.abuse') self.istest(inspect.ismethod, 'git.argue') @@ -91,6 +95,7 @@ def test_isroutine(self): self.assert_(inspect.isroutine(mod.spam)) self.assert_(inspect.isroutine([].count)) + self.assert_(inspect.isroutine(String.toUpperCase)) class TestInterpreterStack(IsTestBase): def __init__(self, *args, **kwargs):