[Python-ideas] Importing orphaned bytecode files (was: disabling .pyc and .pyo files)

Jared Grubb jared.grubb at gmail.com
Wed Dec 9 20:07:54 CET 2009


On 8 Dec 2009, at 13:44, Ben Finney wrote:
> 
> * A new attribute ‘sys.import_orphaned_bytecode’. If set ‘True’, the
>  interpreter follows the current behaviour. If ‘False’, any bytecode
>  file satisfies an import only if it has a corresponding source file
>  (where “corresponding” means “this source file would, if compiled,
>  result in a bytecode file replacing this one”).

One problem with a sys flag is that it's a global setting. Suppose a package is distributed with only pyc/pyo files, then the top-level __init__.py might flip the switch such that its sub-files can get imported from the pyc/pyo files. But you wouldnt want that flag to persist beyond that.

Another idea is to use a new file extension, which isnt the best solution, but allows the creator to explicitly set what behavior they intended for their files:
  * if a foo.py file exists, then use the existing foo.pyc/pyo as is done today
  * if a foo.py file does not exist, but a foo.pyxxx exists, use it (but file.pyc/pyo is never used, unlike today)
(pyxxx is a placeholder for whatever would be a reasonable name)

Jared
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20091209/01d573eb/attachment.html>


More information about the Python-ideas mailing list