Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

10 views
Skip to first unread message

Chris Angelico

unread,
Oct 9, 2012, 3:06:13 AM10/9/12
to pytho...@python.org
On Tue, Oct 9, 2012 at 1:14 PM, Guido van Rossum <gu...@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. :-)

That wouldn't guarantee that the code would never work, merely that
the 'is' checks would be never true. Dangerous if the condition is a
guard for an unusual condition. A unit test could of course catch it,
but that assumes that everyone who writes "if x is 0" has tests
probing both branches of that check...

ChrisA
0 new messages