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

Peter Hansen peter at engcorp.com
Wed Apr 2 21:57:08 CEST 2003


Jp Calderone wrote:
> 
>   Now, in its current state, it is impossible for the Python interpreter to
> know this.  What if range() is rebound?  So this can't be done now.  But, if
> some of the talk about forbidding the shadowing of builtins bears fruit, it
> might someday be possible for CPython to make this optimization, and all
> without any ugly syntax hacks.

Ouch!  *Forbidding* it?!  That would cripple some of my most sophisticated
and effective unit and acceptance tests!  I dearly hope that "forbid" was
an overly strong choice of verb.

What would be wrong with "discouraging", or "making it clear to the 
compiler when it happens" or something?

Where is this discussion going on, and can I/need I participate to put
forth my perspective on this.  I'm coming to *count* on this as one of
the most effective solutions for certain kinds of testing.  (Specifically,
by creating a mock file system by intercepting open() calls in my own
method, to allow generating of various file system errors and situations
and to increase performance of unit tests by avoiding the real file
system.)

-Peter




More information about the Python-list mailing list