[Python-Dev] ACCEPTED: PEP 285
Christian Tanzer
tanzer at swing.co.at
Thu Apr 4 02:04:09 EST 2002
David Ascher <DavidA at ActiveState.com> wrote:
> > Despite the negative feedback, I've decided to accept the PEP. The
> > most important perceived problem is that newbies tend to write
> >
> > if x == True: ...
> >
> > where they should write
> >
> > if x: ...
> >
> > I believe this problem should be solved by education (the Zen master
> > hits the student on the head with a stick, and the student gets
> > enlightenment) rather than by holding back what I believe will be a
> > useful feature.
>
> Would it not be "relatively" easy to add a compiler-time warning for
> most uses of this dangerous idiom?
>
> At the very least, the boolean type could do the equivalent of:
>
> def __eq__(self, other):
> if __debug__ and other not in (0,1,True,False):
> warnings.warn("Testing of equality is best done by asking
> objects whether they're true, not comparing with a boolean",
> RunTimeWarning)
> return int.__eq__(self, other)
>
> or something similar?
I warning about `x == True` wouldn't hurt. But your proposed `__eq__`
certainly would -- don't do that please.
Equality testing is useful if one wants to check whether two
predicates have the same boolean value.
--
Christian Tanzer tanzer at swing.co.at
Glasauergasse 32 Tel: +43 1 876 62 36
A-1130 Vienna, Austria Fax: +43 1 877 66 92
More information about the Python-list
mailing list