Author fwyzard
Recipients fwyzard
Date 2017-03-07.09:51:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
jython does support the inspect module in a normal .py file:

$ cat
import inspect

def function():
  frame = inspect.currentframe()
  print inspect.getframeinfo(frame)


$java -jar dist/jython-standalone.jar -c 'import test'
Traceback(filename='', lineno=5, function='function', code_context=['  print inspect.getframeinfo(frame)\n'], index=0)

However if the python module is compiled into bytecode this does not work any more

$ python -m py_compile
$ rm
$ java -jar dist/jython-standalone.jar -c 'import pycimport; import test'

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/fwyzard/src/jython/src/dist/Lib/", line 72, in load_module
    return __makeModule( fullname, code, filename )
  File "/home/fwyzard/src/jython/src/dist/Lib/", line 25, in __makeModule
    exec code in module.__dict__
  File "", line 7, in <module>
  File "", line 7, in <module>
  File "", line 5, in function
  File "", line 5, in function
  File "/home/fwyzard/src/jython/src/dist/Lib/", line 1015, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
  File "/home/fwyzard/src/jython/src/dist/Lib/", line 448, in getsourcefile
    filename = getfile(object)
  File "/home/fwyzard/src/jython/src/dist/Lib/", line 423, in getfile
    raise TypeError('{!r} is not a module, class, method, '
TypeError: <code object function at 0x2, file "", line 3> is not a module, class, method, function, traceback, frame, or code object

while it still works as expected with the C python interpreter:

$ python2.7 -c 'import test'
Traceback(filename='', lineno=5, function='function', code_context=None, index=None)

The problem seems to be that code objects from a bytecode file are not of type types.CodeType, but of type org.python.core.PyBaseCode (which is its base class).

A possible fix is to change Lib/ from

CodeType = type(_f.func_code)


CodeType = org.python.core.PyBaseCode

as in the attached patch.

An other possibility would be to change only Lib/ to explicitly check for org.python.core.PyBaseCode in addition to types.CodeType. The change to Lib/ seems more general, though.
Date User Action Args
2017-03-07 09:51:26fwyzardsetmessageid: <>
2017-03-07 09:51:26fwyzardsetrecipients: + fwyzard
2017-03-07 09:51:26fwyzardlinkissue2566 messages
2017-03-07 09:51:26fwyzardcreate