Re: Make "is" checks on non-singleton literals errors
Guido van Rossum <guido@...
2012-10-09 02:14:37 GMT
On Mon, Oct 8, 2012 at 7:03 PM, Steven D'Aprano <steve@...> wrote:
> On Mon, Oct 08, 2012 at 12:48:07PM -0700, Guido van Rossum wrote:
>> On Mon, Oct 8, 2012 at 12:44 PM, Mike Graham <mikegraham@...> 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.
> In my experience beginners barely read error messages, let alone
> A SyntaxWarning might help intermediate users who have graduated beyond
> the stage of "my program doesn't work, please somebody fix it", but I
> believe that at best it will be ignored by beginners, if not actively