Apologies for not being up to speed on the standard bug reporting process. There appears to be an incompatibility between the inspect module and Jython. The inspect module uses "type(xxx) is types.zzz" in a number of places. This seems to fail when inspect is used with Jython. Using "isinstance" instead works as shown in the example below. My understanding is that "isinstance" is the preferred idiom in any case. Jim =========================================== from the inspect module: def iscode(object): """Return true if the object is a code object. Code objects provide these attributes: co_argcount number of arguments (not including * or ** args) co_code string of raw compiled bytecode co_consts tuple of constants used in the bytecode co_filename name of file in which this code object was created co_firstlineno number of first line in Python source code co_flags bitmap: 1=optimized | 2=newlocals | 4=*arg | 8 =**arg co_lnotab encoded mapping of line numbers to bytecode indices co_name name with which this code object was defined co_names tuple of names of local variables co_nlocals number of local variables co_stacksize virtual machine stack space required co_varnames tuple of names of arguments and local variables""" ###return type(object) is types.CodeType # <<< returns 0 (before reload below) return isinstance(object,types.CodeType) # <<< returns 1 (after reload below) Jython 2.1b1 on java1.3.0 (JIT: null) Type "copyright", "credits" or "license" for more information.
from core.probe import tablepanel import inspect source = inspect.getsource(tablepanel.TablePanel.__init__) Traceback (innermost last): File "<console>", line 1, in ? File "C:\_Dev\pnp\3rdparty\jython\Lib\inspect.py", line 411, in getsource File "C:\_Dev\pnp\3rdparty\jython\Lib\inspect.py", line 400, in getsourcelines File "C:\_Dev\pnp\3rdparty\jython\Lib\inspect.py", line 280, in findsource IOError: could not get source code reload(inspect)
source = inspect.getsource(tablepanel.TablePanel.__init__) source " def __init__(self,rowList=None,label=None):\n self.rowList = rowList or [['','','']]\n self.jtable = None\n from javax.swing.table import DefaultTableModel\n self.tabl eModel = DefaultTableModel(self.rowList,self.columnNameList)\n _super.__init__(self,label=lab el)\n"
Apologies for not being up to speed on the standard bug reporting process.
Go to http://sourceforge.net/tracker/?group_id=5470&atid=105470 and click on the "Submit New" link.
There appears to be an incompatibility between the inspect module and Jython.
The inspect module uses "type(xxx) is types.zzz" in a number of places. This seems to fail when inspect is used with Jython.
Using "isinstance" instead works as shown in the example below.
My understanding is that "isinstance" is the preferred idiom in any case.
Indeed. We're going to have to fix inspect.py to work with new types anyway, so we'll try to take care of this. --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (2)
-
Guido van Rossum
-
James_Althoff@i2.com