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


Groups > comp.lang.python > #19062 > unrolled thread

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

Started byAlex Willmer <alex@moreati.org.uk>
First post2012-01-17 09:10 -0800
Last post2012-01-17 19:47 +0100
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  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

#19062 — Finding x is 1, and x is 'foo' comparisons in a code base

FromAlex Willmer <alex@moreati.org.uk>
Date2012-01-17 09:10 -0800
SubjectFinding x is 1, and x is 'foo' comparisons in a code base
Message-ID<6e061ae1-bb46-43bd-ad97-0aff30cc374e@m20g2000vbf.googlegroups.com>
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.

Regards, Alex

[toc] | [next] | [standalone]


#19064

FromMRAB <python@mrabarnett.plus.com>
Date2012-01-17 18:39 +0000
Message-ID<mailman.4817.1326825550.27778.python-list@python.org>
In reply to#19062
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.

[toc] | [prev] | [next] | [standalone]


#19065

FromThomas Heller <theller@ctypes.org>
Date2012-01-17 19:47 +0100
Message-ID<9nlu2pFb0U1@mid.individual.net>
In reply to#19062
Am 17.01.2012 18:10, schrieb Alex Willmer:
> 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.

Pychecker contains a check for this mistake.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web