ugly python namespace bug

Jesper Hertel jh at cddk.dk
Tue Dec 21 05:28:56 EST 1999


As a suggestion, maybe Python could be changed to allow for "constant"
definitions or so. Like

const def type(..):
    ...something...

or

const a = 2

Variables (and functions) declared like this would then have a flag telling
that it is not allowed to change it, and an exception would be raised if
someone tried to do it.

Built-in functions could then be declared like this. One problem by this is
the backwards compatibility. If someone redefines built-in functions in
existing programs, they would not be able to run these programs in new
versions of Python.

I haven't quite thought this through. Just thinking loud...


Jesper Hertel

Roy Smith <roy at popmail.med.nyu.edu> wrote in message
news:roy-1A6F62.16025920121999 at netnews.nyu.edu...
> I had a function which use to look like this:
>
>    for type in stuff:
>       if type == default:
>          etc...
>
> It worked fine, but for one reason or another, I decided to change the
variable
> name from type to option, but forgot to change it in one place, and ended
up
> with:
>
>    for option in stuff:
>       if type == default:
>          etc...
>
> My code stopped working, with the equality test always failing.  I
scratched my
> head a while until I found the problem, but then couldn't figure out why I
> didn't get a name error ("type" undefined) until a co-worker pointed out
that
> type is a built-in function.  My first version of the code just over-wrote
the
> default value of type!
>
> I see how it all works now, but boy, stuff like this sure does invite all
sorts
> of nasty debugging problems!
>
> --
> Roy Smith <roy at popmail.med.nyu.edu>
> New York University School of Medicine
>





More information about the Python-list mailing list