[Python-ideas] Non-boolean return from __contains__
fuzzyman at voidspace.org.uk
Sun Jul 25 23:36:34 CEST 2010
On 25 July 2010 22:32, Jack Diederich <jackdied at gmail.com> wrote:
> On Sun, Jul 25, 2010 at 5:20 PM, Bruce Leban <bruce at leapyear.org> wrote:
> > Let me see if I understand this:
> > False in [False]
> > Returns True now but would return False with your change.
> Bigtime. Official side-effects are neat for hacks but bad for
> maintainable code. You don't know pain until another developer
> complains that you refactored user.is_admin() to no longer return the
> user's object (for the record that happened in perl, but it could in
> python too). Boolean test operations should return bools
Most of them don't and this can be useful. Why should __contains__ enforce
it when other boolean operations don't? Inconsistency is also bad.
> for the same
> reason that in-place operations should return None.
What do you mean by "in-place operations should return None"?
For mutable objects __iadd__ and friends should return self. For immutable
ones they return the new value. Probably I misunderstand what you mean.
> Python-ideas mailing list
> Python-ideas at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas