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

Mike Graham mikegraham at gmail.com
Tue Oct 9 01:05:25 CEST 2012

On Mon, Oct 8, 2012 at 6:42 PM, Serhiy Storchaka <storchaka at gmail.com> wrote:
> On 08.10.12 22:44, Mike Graham wrote:
>> There are no cases where
>>      if x is "foo":
> I see such code in docutils (Doc/tools/docutils/writers/latex2e/__init__.py)

Thanks for finding these!

I can't find this in a couple versions of Python I checked. If this
code is still around, it sounds like it has a bug and should be fixed.

>> or
>>     if x is 4:
> and in tests (Lib/test/test_long.py, Lib/test/test_int.py,
> Lib/test/test_grammar.py, Lib/test/test_winsound.py).

test_grammar.py is correct, but trivially so. It merely ensures that
`1 is 1` and `1 is not 1` are proper Python syntax. As we're talking
about tweaking Python's syntax rules, obviously code that tests that
the grammar is the current thing would use the current thing.

test_int.py and test_long.py are valid but unique, in that they rely
on the behavior that no other code should implicitly rely on to test
an implementation detail

test_winsound.py has an `is 0` check and an `is ""` check. Both should be fixed.

Thanks again,

More information about the Python-ideas mailing list