[Python-ideas] Make Python code read-only
Chris Angelico
rosuav at gmail.com
Tue May 20 19:44:43 CEST 2014
On Wed, May 21, 2014 at 3:36 AM, Peter Mawhorter <pmawhorter at gmail.com> wrote:
> The main cost I can see here is in
> maintaining the readonly mode and the perhaps subtle bugs that would
> arise in many people's code when run in readonly mode.
Here's a stupid-crazy idea to chew on. (Fortunately this is not
python-good-ideas at python.org - I wouldn't have much to contribute
there!) Make the per-module flag opt-in-only, but the overall
per-application flag active by default. Then, read-only mode applies
to a small number of standard library modules (plus any user modules
that specifically request it), and will thus be less surprising; and a
small rewording of the error message (eg "... - run Python with the
-O0 parameter to disable this check") would mean the monkey-patchers
could still do their stuff, at the cost of this optimization. It's
less likely to be surprising, because development would be done with
read-only mode active, rather than "Okay, let's try this in optimized
mode now - no asserts and read-only dicts... oh dear, it's not
working".
Big downside: Time machine policy prevents us from going back to 2.0
and implementing it there. There's going to be an even worse boundary
when people upgrade to a Python with this active by default. So it's
probably better to NOT make either half active by default, but to
recommend that new projects be developed with read-only mode active.
ChrisA
More information about the Python-ideas
mailing list