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

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!nuzba.szn.dk!pnx.dk!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'pointer': 0.05; 'subject:code': 0.07; 'python': 0.08; 'comparisons': 0.09; 'from:addr:python': 0.09; 'none)': 0.09; 'string)': 0.09; 'willmer': 0.09; "subject:' ": 0.15; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'occurrences': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'reply-to:addr:python-list': 0.16; 'wrote:': 0.16; 'header:In-Reply-To:1': 0.22; 'base.': 0.23; 'tool,': 0.23; 'welcome.': 0.23; 'code': 0.25; "i'm": 0.27; 'script.': 0.28; 'mistakes,': 0.30; '(e.g.': 0.30; 'alex': 0.30; 'usually': 0.30; 'correct': 0.31; 'cases': 0.32; 'header:User- Agent:1': 0.33; 'to:addr:python-list': 0.33; 'received:84': 0.34; 'integer': 0.34; 'reply-to:addr:python.org': 0.34; 'suggestions': 0.35; 'test': 0.35; 'hello,': 0.37; 'using': 0.37; 'except': 0.39; 'either': 0.39; 'being': 0.39; 'tool': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'most': 0.60; 'happen': 0.61; 'special': 0.67; 'as:': 0.70; 'header:Reply-To:1': 0.71; 'production': 0.71; 'reply-to:no real name:2**0': 0.72; 'slip': 0.91
X-CM-Score 0.00
X-CNFS-Analysis v=2.0 cv=A/buztqG c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=9jsOeB20M3cA:10 a=W0_hhh8VKs8A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EuZrldbSWjePpaOLaBgA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH mrabarnett:2500
Date Tue, 17 Jan 2012 18:39:13 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20111105 Thunderbird/8.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Finding x is 1, and x is 'foo' comparisons in a code base
References <6e061ae1-bb46-43bd-ad97-0aff30cc374e@m20g2000vbf.googlegroups.com>
In-Reply-To <6e061ae1-bb46-43bd-ad97-0aff30cc374e@m20g2000vbf.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4817.1326825550.27778.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1326825550 news.xs4all.nl 6916 [2001:888:2000:d::a6]:49413
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19064

Show key headers only | 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