[Python-ideas] Make Python code read-only
Chris Angelico
rosuav at gmail.com
Wed May 21 00:46:04 CEST 2014
On Wed, May 21, 2014 at 6:32 AM, Victor Stinner
<victor.stinner at gmail.com> wrote:
> 2014-05-20 19:37 GMT+02:00 Chris Angelico <rosuav at gmail.com>:
>>> * The sys module cannot be made read-only because modifying sys.stdout
>>> and sys.ps1 is a common use case.
>>
>> I think this highlights the biggest concern with defaulting to
>> read-only.
>
> Hum, maybe my email was unclear: the read-only mode is disabled by default.
>
> When you enable the read-only mode, all modules are read-only except
> the modules explicitly configured to be modifiable.
There are two read-only states:
1) Is this application running in read-only mode? (You give an example
of setting this by an env var.)
2) Is this module read-only? (You give an example of setting this to False.)
It's the second one that I'm talking about. If, once you turn on
read-only mode (the first state), every module is read-only except
those marked __readonly__=False, you're going to have major backward
incompatibility problems. All it takes is one single module that ought
to be marked __readonly__=False and isn't, and read-only mode is
broken. Yes, it may be that most of the standard library can be made
read-only; but I believe it would still be better to explicitly say
__readonly__=True on each of those modules, than __readonly__=False on
the others - because of all the *non* stdlib modules.
ChrisA
More information about the Python-ideas
mailing list