Message3805

Author pjenvey
Recipients cgroves, leouserz, pjenvey
Date 2008-11-22.21:35:50
SpamBayes Score 1.7136292e-13
Marked as misclassified No
Message-id <1227389751.33.0.284741986414.issue1605847@psf.upfronthosting.co.za>
In-reply-to
Content
Came across this bug while attempting to fix __file__ to use the 
compiled filename ( #1138 ).

CPython's co_filename actually doesn't always match __file__, it's 
hardcoded to the original source code filename (at least in 2.5). So we 
actually didn't need to do this:

(jython)pjenvey@golgo13:/tmp$ cat whereami/__init__.py
print 'top level %s' % __file__
def foo():
    pass
print foo.func_code.co_filename
(jython)pjenvey@golgo13:/tmp$ /usr/bin/python
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import whereami
top level whereami/__init__.py
whereami/__init__.py
>>> ^D
(jython)pjenvey@golgo13:/tmp$ /usr/bin/python
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import whereami
top level whereami/__init__.pyc
whereami/__init__.py
>>> ^D
(jython)pjenvey@golgo13:/tmp$ cd whereami/
(jython)pjenvey@golgo13:/tmp/whereami$ /usr/bin/python
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import __init__ 
top level __init__.pyc
whereami/__init__.py
>>> ^D

It's nicer that we did but it requires us to unnecessarily pass in a 
source code filename when loading a class. We already do this for 
__file__, but I'm changing this (__file__ will now always be explicitly 
set by imp instead of having the compiler involved).

Not a big deal, just wanted to document this oddness somewhere =]
History
Date User Action Args
2008-11-22 21:35:51pjenveysetmessageid: <1227389751.33.0.284741986414.issue1605847@psf.upfronthosting.co.za>
2008-11-22 21:35:51pjenveysetrecipients: + pjenvey, cgroves, leouserz
2008-11-22 21:35:51pjenveylinkissue1605847 messages
2008-11-22 21:35:50pjenveycreate