[Patches] In overloading: not special casing strings

Guido van Rossum guido@python.org
Tue, 07 Mar 2000 10:47:49 -0500


> > Thanks.  There's one thing broken in this version: you made the test
> > for length==1 return false -- it should raise an exception.  See the
> > patches:
> 
> Yes. Undocumented feature (which will be documented in a seperate doc
> patch once these get in). I have moral problems with raising an exception
> as a result of a "test containment" operation. An ADT of container either
> contains something, or it does not. Anything else is an optimization.

Moral problems or not, it's a feature that I don't want to remove.  If
my code uses (i in s) where s is a string and i is an int, this would
always be false -- probably it is a bug in the code, and that's why I
raise an exception.  Same with non-length-1 character strings.  A
newbie could easily believe that "bc" in "abcd" should return 1 --
rather than having them puzzle why it doesn't work (they probably
tried ("xyz" in "abc") first and found that it correctly returned 0
:-), I give them an error explaining that it doesn't work that way.

> <snipped code>
> > See: this is the exception I'm talking about.
> 
> The reference manual sorts of says this behaviour is nasty.

Where?  Which behavior?

I'd say that it's nasty behavior to send in a patch whose documented
purpose is to move some code from one file to another but which
silently also turns an exception into a "false" return. :-)

--Guido van Rossum (home page: http://www.python.org/~guido/)