For various reasons reportlab makes wheels that have some modules issued in compiled form and each such module is loaded by a stub trampoline module which overwrites itself.
That has caused a problem with some exception handling tools which expect the linecache to hold the source of modules which end up raising or propagating an exception.
Is there a way for the trampoline stub to remove itself from the linecache? That would at least prevent any confusion if the error lineno falls into the range of the trampoline lines.
The undocumented structure of linecache.cache is a dict mapping file names to a list of 1 or 4 items. The single item list is for the lazycache mechanism; 4 is for normal source files. linecache.cache.pop(filename) currently works to remove a filename and its list, and is used within linecache.py itself.
‘Undocumented’ theoretically means ‘subject’ to change, but I would not be surprised if enough code already depends on internals to make this difficult. idlelib.pyshell uses .pop.
I do not completely understand the lazycache feature, but if ‘compiled form’ means ‘compiled from Python source’, I wonder if it could be used to make the source lines available for tracebacks.
Unfortunately the idea of putting compiled code into the wheel is to obfuscate the original source (I know that logic and structure can be obtained using a decompiler). So I would say no to making lazycache a source for the error code. The running code has no access to the original source.
The bootstrapping code is only 17 lines long so I can use a comment or doc string at the top of the obfuscated modules to at least make any reported error lineno either properly in the bootstrap or invalid if it’s in the hidden code.
Perhaps I misunderstood your comment; are you implying that lazycache could be used to supply some fake lines of source so allowing the traceback tool to proceed more normally?