[Python-Dev] how important is setting co_filename for a module being imported to what file is set to? (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Tue Sep 1 12:36:46 CEST 2009


Fred Drake wrote:

Every time I've been bitten by the wrong cofilename values (usually from tracebacks), changing the way marshal creates code objects to use a values passed in has been the thing that made the most sense to me.

The feature request that's involved here, getting correct cofilename values, can be implemented in different ways, sure. This particular change produces the least impact in the because it doesn't change the mutability of code objects. I for one appreciate that, mostly because I'm simply wary of making code objects mutable in this way having unexpected side effects in some library.

"linecache" was the one that immediately popped into mind for me (not saying it is affected, just saying it would be the first place I would like for possible side effects).

I think this is one of those situations where something has behaved a certain way for so long that it would be really hard to be confident that we had considered all the possible ramifications of changing it.

Modifying marshal to allow Python code to override the stored value instead of making it a free-for-all preserves the post-compile immutability characteristic while still letting Brett make importlib mimic the behaviour of import.c.

Cheers, Nick.

-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia



More information about the Python-Dev mailing list