This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author stefan.mueller
Recipients stefan.mueller
Date 2014-01-09.13:18:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1389273529.73.0.188399599981.issue20205@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-01-09 13:18:49stefan.muellersetrecipients: + stefan.mueller
2014-01-09 13:18:49stefan.muellersetmessageid: <1389273529.73.0.188399599981.issue20205@psf.upfronthosting.co.za>
2014-01-09 13:18:49stefan.muellerlinkissue20205 messages
2014-01-09 13:18:49stefan.muellercreate