[Python-Dev] PEP 329: Treating Builtins as Constants inthe
Phillip J. Eby
pje at telecommunity.com
Mon Apr 19 20:43:49 EDT 2004
At 05:23 PM 4/19/04 -0700, Guido van Rossum wrote:
> > This suggests that there should be some way of disabling
> > the optimisation from *outside* the module. Not sure what
> > that would be, though.
>A command line flag?
For that to work, there'd need to be some place to store the names of the
modules to which one wished to apply this "pessimization". That being the
case, one might as well expose an API to Python for that, rather than
forcing the issue up to the command line and thereby reducing modularity,
as well as possibly being an issue for embedders, Jython, et al.
Anyway, the API would give you a function to call if you want to disable
optimization for a module in order to monkeypatch it. That function would
then raise an error if the module in question was already imported with
optimization enabled, or if the runtime environment disallows such changes
(e.g. if Jython, IronPython, or various hypothetical
Python-to-static-language translators want to disallow monkeypatching).
One possibly interesting use case is Pyrex, which would like to be able to
disallow modifications to built-ins in order to translate e.g. 'len()' into
C. It would be nice if there's a way for C modules to "play nice" with the
mechanisms under discussion. Specifically, if there's a way for them to
declare metadata of the same sort that's contemplated for indicating what
attributes of a module are modifiable from outside.
More information about the Python-Dev