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

Guido van Rossum guido at python.org
Mon Oct 8 21:48:07 CEST 2012


On Mon, Oct 8, 2012 at 12:44 PM, Mike Graham <mikegraham at gmail.com> wrote:
> I regularly see learners using "is" to check for string equality and
> sometimes other equality. Due to optimizations, they often come away
> thinking it worked for them.
>
> There are no cases where
>
>     if x is "foo":
>
> or
>
>    if x is 4:
>
> is actually the code someone intended to write.
>
> Although this has no benefit to anyone but new learners, it also
> doesn't really do any harm.

I think the best we can do is to make these SyntaxWarnings. I had the
same thought recently and I do agree that these are common beginners
mistakes that can easily hide bugs by succeeding in simple tests.

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list