A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2004-April/044506.html below:

[Python-Dev] peps 329, 266, 267

[Python-Dev] peps 329, 266, 267Skip Montanaro skip at pobox.com
Wed Apr 21 15:59:24 EDT 2004
    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


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4