[Python-ideas] Make "is" checks on non-singleton literals errors
Devin Jeanpierre
jeanpierreda at gmail.com
Tue Oct 9 23:32:33 CEST 2012
On Mon, Oct 8, 2012 at 10:14 PM, Guido van Rossum <guido at python.org> wrote:
> Maybe we should do something more drastic and always create a new,
> unique constant whenever a literal occurs as an argument of 'is' or
> 'is not'? Then such code would never work, leading people to examine
> their code more closely. I betcha we have people who could change the
> bytecode compiler easily enough to do that. (I'm not seriously
> proposing this, except as a threat of what we could do if the
> SyntaxWarning is rejected. :-)
Is this any better than making `x is 0` raise a TypeError with a
message about what's wrong (as suggested by Mike Graham)?
In both cases, `x is 0` is basically worthless, but at least if it
raises an exception people can understand what "went wrong", because
of the error message that comes with the exception.
-- Devin
More information about the Python-ideas
mailing list