New submission from Stefan Müller:

Following situation

* python 2.7.6

* module loaded via a PEP302 loader.

* the loader has get_source(fullname)

* assigns a dummy string as a file: module.__file__ == "<mymodule>"

Then

inspect.getsource(module)

throws

IOError: could not get source code

I tired to track this down, and it seems to be caused by  
linecache.updatecache(..) with has

    if not filename or (filename.startswith('<') and filename.endswith('>')):
        return []

at the beginning.

This seems too restrictive me. Without the 'if' it would try to read the file 
from disk, and if that fails check if there is a loader, without a loader it 
returns [], so there would not be any behaviour change for non-loader modules 
if the 'if' was removed, only an additional disk access.

I suggest to remove the 'if'.

Workaround: Don't use '<>' for the dummy file name, but I've read somewhere 
that those '<>' are a convention for such use-cases.

----------
components: Library (Lib)
messages: 207736
nosy: stefan.mueller
priority: normal
severity: normal
status: open
title: inspect.getsource(), P302 loader and '<..>' filenames
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue20205>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to