Tricky Areas in Python
aleaxit at yahoo.com
Tue Oct 25 16:54:55 CEST 2005
Fredrik Lundh <fredrik at pythonware.com> wrote:
> Alex Martelli wrote:
> >> > class Sic:
> >> > def getFoo(self): ...
> >> > def setFoo(self): ...
> >> > foo = property(getFoo, setFoo)
> > Sorry for skipping the 2nd argument to setFoo, that was accidental in my
> > post. The problem here is: class Sic is "classic" ("legacy",
> > "old-style") so property won't really work for it (the setter will NOT
> > trigger when you assign to s.foo and s is an instance of Sic).
> what's slightly confusing is that the getter works, at least until you attempt
> to use the setter:
Oh yes, that IS definitely contributing to the confusion -- which is
part of why I think it makes sense to claim this is a "tricky area".
> (a "setter isn't part of an new-style object hierarchy" exception would have
> been nice, I think...)
Agreed. Alas, a bit too late now, I fear (until 3.0 when old-style goes
away) -- somebody might be (unwisely but "it-sort-of-works" style)
relying on this behavior. Hmmm, maybe a WARNING could be given...
More information about the Python-list