3

Closed

co_filename in code objects is None

description

<FixedIn>1.1</FixedIn>
<Test>test_function</Test>
<Thanks>Christian Muirhead</Thanks>
 
CPython:
 
c = compile("x = 2", "test", "exec") >>> c.co_filename 'test'
 
IronPython 1.0.1
 
c = compile("x = 2", "test", "exec") >>> c.co_filename >>>
 
(That is, it was None)
 
It would be handy for us if IP's behaviour matched CPython's here. Can you please add a bug for this?
Closed Jul 21, 2008 at 10:19 PM by dfugate

comments

sanxiyn wrote Dec 3, 2006 at 12:48 PM

Patch: http://fepy.sourceforge.net/patches.html (patch-ironpython-compile-co-filename)

dfugate wrote Apr 22, 2008 at 10:05 PM

Works in 2.0 as well now. Enabled regression tests.

** Closed by dfugate 9/26/2007 10:47 AM

dfugate wrote Apr 22, 2008 at 10:05 PM

dfugate wrote Apr 22, 2008 at 10:24 PM

Reopened this as I've found another scenario it fails in:

E:\Merlin\External\Languages\IronPython20\25\Lib>type E:\blah.py
import sys

from new import module
name = '__inspect_dummy'
m = sys.modules[name] = module(name)
m.file = "<string>"
m.loader = "dummy"
exec "def x(): pass" in m.dict

print m.x.func_code.co_filename
E:\Merlin\External\Languages\IronPython20\25\Lib>cpy E:\blah.py
<string>

E:\Merlin\External\Languages\IronPython20\25\Lib>ipyd E:\blah.py
None

dinov wrote Jun 4, 2008 at 8:42 PM

we need to check for the filename from CodeContext if we don't get one from the source file. We don't always pull it from globals because:

file = 'abc'
def f(): pass

f.func_code.co_filename

still has the real filename