[Python-ideas] Make "is" checks on non-singleton literals errors

Georg Brandl g.brandl at gmx.net
Tue Oct 9 22:15:42 CEST 2012


Am 08.10.2012 22:38, schrieb Joshua Landau:

>     Conversely, I often see this:
> 
>         if x == None
> 
>     and even
> 
>         if x == True
> 
>     Okay, so maybe these are less harmful than the original complaint, but still,
>     yuck!
> 
> 
> We can't really warn against these.
> 
>     >>> class EqualToTrue:
>     ...     def __eq__(self, other):
>     ...             return other is True
>     ... 
>     >>> EqualToTrue() is True
>     False
>     >>> EqualToTrue() == True
>     True

The point is that in 99.9...% of cases,

  if x == True:

is just

  if x:

Georg




More information about the Python-ideas mailing list