[Python-Dev] towards a faster Python

Paul F Dubois paul@pfdubois.com
Mon, 9 Jun 2003 15:53:07 -0700


Some builtins have names that are "obvious", such as "open". That makes them
"obvious" names to want to use in other contexts. For example, I have a
module mykindoffile and I want to be able to say mykindoffile.open('xxxx').

Imagine that mykindoffile is in Python; then mykindoffile.py might want to
define open using an underlying extension:

import _mykindoffile
open = _mykindoffile.open

Now imagine that mykindoffile is a package. I might have in
mykindoffile/__init__.py something like:

from myopener import open

Now in all these cases I am setting an attribute in a module, but in a way
that Python could detect when compiling mykindoffile. This is the kind of
thing I do all the time.

But there are, as noted, cases where Python cannot reasonably see what you
are doing such as:
mykindoffile.open = myopenf
exec 'open=_mykindoffile.open' in mykindoffile 

I feel that being able to use names like open is important, but it would be
a rats nest to say that there were some ways you could do it and succeed,
some that gave warning errors and might or might not fail, and some that
could mysteriously fail without warning.

Making a module dictionary readonly after importation would break legendary
amounts of code. In fact, what I wish all the time is that a module was a
kind of singleton class instance so that I could use properties,
descriptors, etc. in it.