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

Skip Montanaro skip at pobox.com
Thu Apr 3 01:59:52 CEST 2003


    Tim> I think that nearly this exact use case was discussed here:
    Tim> http://mail.python.org/pipermail/python-dev/2003-March/034272.html
    Tim> . If you go forward a few messages, GVR suggests adding "from
    Tim> __builtins__ import open" to modules that you might want to fiddle
    Tim> with.

Yeah, but that's quite different from Peter's use case, where he wants to
unit test a module more-or-less from the outside.  He shouldn't have to add
hooks in the module itself to unit test it.

    Tim> This made me recall that the proposal was slightly more lenient
    Tim> than I initially remembered:

    Tim> some_random_module.open = my_open

    Tim> would be OK if open is already shadowed in some_random_module. The
    Tim> compiler then can figure out that optimizing access to open is not
    Tim> going to work.

That won't help Peter either.  I suspect all of the modules he wants to test
don't actually shadow open().

Skip





More information about the Python-list mailing list