[Python-ideas] Move optional data out of pyc files

Serhiy Storchaka storchaka at gmail.com
Tue Apr 10 12:14:58 EDT 2018

Currently pyc files contain data that is useful mostly for developing 
and is not needed in most normal cases in stable program. There is even 
an option that allows to exclude a part of this information from pyc 
files. It is expected that this saves memory, startup time, and disk 
space (or the time of loading from network). I propose to move this data 
from pyc files into separate file or files. pyc files should contain 
only external references to external files. If the corresponding 
external file is absent or specific option suppresses them, references 
are replaced with None or NULL at import time, otherwise they are loaded 
from external files.

1. Docstrings. They are needed mainly for developing.

2. Line numbers (lnotab). They are helpful for formatting tracebacks, 
for tracing, and debugging with the debugger. Sources are helpful in 
such cases too. If the program doesn't contain errors ;-) and is sipped 
without sources, they could be removed.

3. Annotations. They are used mainly by third party tools that 
statically analyze sources. They are rarely used at runtime.

Docstrings will be read from the corresponding docstring file unless -OO 
is supplied. This will allow also to localize docstrings. Depending on 
locale or other settings different docstring file can be used.

For suppressing line numbers and annotations new options can be added.

More information about the Python-ideas mailing list