Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19064

Re: Finding x is 1, and x is 'foo' comparisons in a code base

Date 2012-01-17 18:39 +0000
From MRAB <python@mrabarnett.plus.com>
Subject Re: Finding x is 1, and x is 'foo' comparisons in a code base
References <6e061ae1-bb46-43bd-ad97-0aff30cc374e@m20g2000vbf.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.4817.1326825550.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 17/01/2012 17:10, Alex Willmer wrote:
> Hello,
>
> I'm looking for a way to find the occurrences of x is y comparisons in
> an existing code base. Except for a few special cases (e.g. x is [not]
> None) they're a usually mistakes, the correct test being x == y.
> However they happen to work most of the time on CPython (e.g. when y
> is a small integer or string) so they slip into production code
> unnoticed.
>
> PyLint and PyFlakes don't check this AFAICT. Any suggestions for such
> a tool, or a pointer how to add the check to an existing tool would be
> most welcome.
>
I would search using a regex such as:

     \bis\b(?! +None| +not +None)

in either a text editor or using a Python script.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Finding x is 1, and x is 'foo' comparisons in a code base Alex Willmer <alex@moreati.org.uk> - 2012-01-17 09:10 -0800
  Re: Finding x is 1, and x is 'foo' comparisons in a code base MRAB <python@mrabarnett.plus.com> - 2012-01-17 18:39 +0000
  Re: Finding x is 1, and x is 'foo' comparisons in a code base Thomas Heller <theller@ctypes.org> - 2012-01-17 19:47 +0100

csiph-web