[Tutor] pychecker: x is None or x == None

Kent Johnson kent37 at tds.net
Fri Aug 12 15:51:14 CEST 2005

Duncan Gibson wrote:
> We've been programming in Python for about a year. Initially we had a
> lot of tests of the form
>     if x == None:
>         do_something()
> but then someone thought that we should really change these to
>     if x is None:
>         do_something()
> However. if you run pychecker on these two snippets of code, it
> complains about the second, and not the first:
>     x.py:6: Using is None, may not always work
> So the question is, which one should we really be using?
> If it is the second, how do I get pychecker to shut up?

Searching comp.lang.python for 'pychecker "is None"' finds this discussion:

which says that pychecker is confused by the comparison to a constant and you should ignore it.

There is a pychecker test (test_input\test90.py and test_output\test90) which shows pychecker ignoring 'is not None' so I think this is a pychecker bug in Python 2.4. It is in the bug tracker here:

The bug references PEP 290 which clearly says that 'is None' is the preferred test:

I don't see a way to turn off this test but I haven't looked in detail at the config options.


More information about the Tutor mailing list