Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Finding x is 1, and x is 'foo' comparisons in a code base

Reply
Thread Tools

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

 
 
Alex Willmer
Guest
Posts: n/a
 
      01-17-2012
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
 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      01-17-2012
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.
 
Reply With Quote
 
 
 
 
Thomas Heller
Guest
Posts: n/a
 
      01-17-2012
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
base class public type (non template and template base class) Hicham Mouline C++ 1 04-20-2009 03:28 PM
Derived::Derived(const Base&) and Derived& operator=(const Base&) developereo@hotmail.com C++ 1 05-23-2007 01:44 PM
Derived::Derived(const Base&) and Derived& operator=(const Base&) developereo@hotmail.com C++ 1 05-23-2007 12:07 AM
sizeof(EmptyStruct) in C and C++ (was: Base {}; sizeof(Base) == 1?) Alex Vinokur C Programming 7 08-14-2006 04:57 PM
self.included(base) and base.class_eval problems, etc. n8agrin@gmail.com Ruby 2 03-08-2006 01:53 PM



Advertisments