Overloading and? was <RE: Should I prefer an external database>

A. Lloyd Flanagan alloydflanagan at attbi.com
Tue Apr 22 20:49:11 CEST 2003


"Bjorn Pettersen" <BPettersen at NAREX.com> wrote in message news:<mailman.1051023275.29338.python-list at python.org>...
> > From: Ian Bicking [mailto:ianb at colorstudy.com] 
> [... + SQLObject example]
> 
> > for paper in Paper.select(AND(Paper.q.title == 'foo',
> >                               Paper.q.author.startswith('Bob'))):
> 
> Does anyone know the reason for not allowing an overload of the and
> operator? (of course, the only use case I've seen is the one above
> [thrice, first time in 97] and alternate logical calculi [e.g. fuzzy
> logic] -- so not much different from some of the other operators? :-)
> 
> -- bjorn

I'm going to guess it's because a) it's a boolean operation, not an
arithmetic one, and therefore b) overloading it could cause incredible
mischief with the language.  Imagine:
class C:
  def __and__(self, some_other_thing):
     return (self or some_other_thing)

Now suddenly if statements don't work for some objects, all kinds of
internal code probably fails for no apparent reason, etc.
Other reasons would be performance impact on a fundamental language
construct, and possibly that no one could think of a good reason why
you'd want to do that.




More information about the Python-list mailing list