What's up with rebinding assignment?

Ulrich Petri ulope at gmx.de
Fri Mar 21 15:24:23 EST 2003


"Jp Calderone" <exarkun at intarweb.us> schrieb im Newsbeitrag
news:mailman.1048270535.12131.python-list at python.org...
>
>   Why is rebinding a variable from a nested scope a design flaw, if
reading
> it is not?
>
>   In my unit tests, I tend to have a lot of things like this:
>
> [snip unittest]
>
>   Why should assignment to an attribute of a name in an outer scope be any
> different from assignment to an actual outer name?  Or does this code
> have a serious design flaw? ;)

Perhaps i didn't made myself very clear.
I your case you are changing an attribute of self, not self-the-thing.

What i wanted to say is that no deeper scope should be able to change a
higher level variable.
I.e.

class dummy:
    def __init__(self):
        pass

class blah:
    self.my_special_var = "something"
    def method1(self):
        def method2():
            self === dummy()         #this should symbolise this funky new
rebinding operator
    method2()
    return self.my_special_var     #now youre fu*ked


>   Making "authenticated" global would be an ugly hack, I have some twenty
of
> these tests (for -just- this protocol).  It's been a -long- time since I
was
> a bad enough programmer to have twenty globals in my program ;)
>
>   And as I see it, having it as an attribute of "self" is an ugly hack as
> well.  It -is- local to testAuthenticate.  Nothing else needs it, -ever-.

actually it is an attribute of self... try it

Ciao Ulrich








More information about the Python-list mailing list