[Python-Dev] peps 329, 266, 267 (original) (raw)
Skip Montanaro skip at pobox.com
Wed Apr 21 15:59:24 EDT 2004
- Previous message: [Python-Dev] peps 329, 266, 267
- Next message: [Python-Dev] peps 329, 266, 267
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Jim> If you really want to track changes to builtin, it is still faster
Jim> to echo builtin changes across each module than it would be to
Jim> track every name's referrers in every module (as in PEP 266.)
This is an interesting idea but still has a problem (which I think can be worked around). Most python apps will rarely create module-level shadows of builtins, however if they do you have to recognize that fact when propagating new values out to the modules. Updating an object in builtins will look something like:
def update_builtin_object(name, val):
"update builtins with new value and update shadows"
old = getattr(__builtins__, name)
for modname in sys.modules:
mod = sys.modules[modname]
if hasattr(mod, name):
modglob = getattr(mod, name)
if modglob != old:
# module has a distinct shadow - don't mess w/ it
continue
setattr(mod, name, val)
else:
# module doesn't have a copy of name - give it one
setattr(mod, name, val)
This guarantees that a module's globals will have a copy of each builtin. If the programmer wants to shadow the original value of a builtin object and remain immune to changes to builtins, it suffices to copy it into a different name and use that:
mylen = __builtins__.len
This gets you halfway there. The globals dict now has a copy of builtins. It's necessary to implement something like Jeremy's dlict object to get full performance boost.
Skip
- Previous message: [Python-Dev] peps 329, 266, 267
- Next message: [Python-Dev] peps 329, 266, 267
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]