Shadowing builtins (was Re: a pyrex-inspired for-i-from-1-to-n...)

Skip Montanaro skip at pobox.com
Wed Apr 2 17:13:41 EST 2003


    >> How about calling new.module() to create a new module object from the
    >> one you want to test which has suitably munged globals?

    Peter> Interesting idea... but ...
    ...
    Peter> # install mock open again
    Peter> mungedMut.open = mockOpen

    Peter> What I don't understand is the difference between the final line
    Peter> above and what I was originally trying to do, except that this is
    Peter> a newly created module instead of one that was imported.

    Peter> Okay, I guess I must have missed a key point and I'm way off the 
    Peter> track here.  Please clarify.

No, it turns out I was.  I was thinking you passed a bunch of stuff (like a
dict to use as globals()) to new.module().  I guess I was thinking of
new.code() and new.function().  You might be able to poke elements directly
into the module's __dict__.  Perhaps new.module can grow an optional dict
argument to handle this sort of thing.

I suggest you post your use case to python-dev as something for people there
to think about.  In fact, new.module() would become pretty useless if you
weren't able to do what you can do today, so I think it will probably need a
dict argument if the "no modifying another module's globals" restriction is
implemented.

Skip






More information about the Python-list mailing list