What's up with rebinding assignment?

Jp Calderone exarkun at intarweb.us
Fri Mar 21 15:55:39 EST 2003


On Fri, Mar 21, 2003 at 09:24:23PM +0100, Ulrich Petri wrote:
> 
> "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.
> 

  Of this fact I am well aware.  As I mention below, I feel this to be an
ugly hack.

> What i wanted to say is that no deeper scope should be able to change a
> higher level variable.
> I.e.
> 
> [snip inner scope rebinds names in outer scope]

  Yes.  This is what I want to do.

> 
> >   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
> 

  Yes, it is.  It is "conceptually" local.  No other code uses it.  So, why
should it be an attribute of the instance?  It is bound at the beginning of
the method and discarded at the end.

  I want to be able to rebind names in the enclosing scope.

  Jp

--
"Pascal is Pascal is Pascal is dog meat."
                -- M. Devine and P. Larson, Computer Science 340
-- 
 up 1 day, 15:59, 6 users, load average: 0.00, 0.01, 0.03





More information about the Python-list mailing list