Typed python comparison / code analysis questions

Ian Kelly ian.g.kelly at gmail.com
Wed Jan 4 15:34:23 EST 2012


On Wed, Jan 4, 2012 at 1:09 PM, Lucas Vickers <lucasvickers at gmail.com> wrote:
> Hello,
>
> I'm relatively new to Python.  I come from C/C++ so I love the flexibility
> but I am slightly irked by the lack of compilation time checking.
>
> I've got two questions
> 1) Are there any tools that do an analysis of code and attempt to catch
> potential issues such as undefined variables, etc?  I use xdebug in php for
> this purpose and it's a life saver.  Currently for Python I use module test
> cases and simulate situations but this doesn't catch everything and on a
> larger scale of development becomes difficult.

Yes, try pylint, pychecker, or pyflakes.



> 2) Is there a way to error when comparing variables of different types?  I
> was up late last night coding and caused a few bugs with the below code,
> which turns out to compare a type<str> to a type<int>.  I know good
> programming I should know what my variable types are, but it would be even
> better if I could always abide by a rule of using <_ (or something) which
> would spit an exception when comparing non-equal types/instances.

This is a well-known wart in Python 2.  The recommended solution would
be to upgrade to Python 3, which no longer allows ordered comparisons
between unrelated built-in types.

Cheers,
Ian



More information about the Python-list mailing list