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


Groups > comp.lang.python > #18513

Re: Typed python comparison / code analysis questions

References <CAH0oNN+cT4WqM+M+Ne9eOfFL4y71sG84XqYDo+NAkLp-w1kVjw@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-01-04 13:34 -0700
Subject Re: Typed python comparison / code analysis questions
Newsgroups comp.lang.python
Message-ID <mailman.4425.1325709295.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Jan 4, 2012 at 1:09 PM, Lucas Vickers <lucasvickers@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

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


Thread

Re: Typed python comparison / code analysis questions Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-04 13:34 -0700

csiph-web