[Python-Dev] how important is setting co_filename for a module being imported to what __file__ is set to?

Antoine Pitrou solipsis at pitrou.net
Mon Aug 31 15:32:53 CEST 2009


Nick Coghlan <ncoghlan <at> gmail.com> writes:
> 
> I thought of that question as well, but the later exchange between Guido
> and Brett made me realise that a lot more than the top level module code
> object is affected here - the adjustment also needs to be propagated to
> the code objects created by the module for functions and generators and
> so forth.

I'm not sure I understand. There's a single type of "code object" and it's
PyCodeObject. Making the attribute writable (from Python code) at that level
should be sufficient.
(then of course the recursive machinery needed to mutate all code objects
created in a module may be slightly inefficient if written in Python, but at
least it's possible to write it)

Regards

Antoine.




More information about the Python-Dev mailing list