[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: static analysis and other tools for checking Python code



Hi,

On Fri, Mar 04, 2016 at 01:03:17PM +0800, Paul Wise wrote:
> > That would be https://pypi.python.org/pypi/PyChecker
> > 
> > Pylint has never run code from the source tree.
> 
> I wonder where I got that impression from.
> 
> What about from the module it is checking?
> 
> > "pylint <themodule>" should work fine.
> 
> Unfortunately that needs the module installed to work.
> 
> Is there any way to make it scan the source tree instead?

It *does* read the source and scan the tree.

It *does*not* import or execute the code.

That is the very first goal of pylint: "detect code smells in python
code by staticaly analyzing the syntax tree read from the source".

  $ cat foo.py
  a = b+1
  $ pylint -E foo.py
  No config file found, using default configuration
  ************* Module foo
  E:  1, 4: Undefined variable 'b' (undefined-variable)
  $ mkdir bar
  $ mv foo.py bar
  $ touch bar/__init__.py
  $ pylint -E bar/
  No config file found, using default configuration
  ************* Module bar.foo
  E:  1, 4: Undefined variable 'b' (undefined-variable)

There is even a library named https://pypi.python.org/pypi/astroid
that was extracted out of pylint to make it easier for other tools to
do type inference (and other things) on Python's Abstract Syntax
Trees.

I hope this helps making clearer what pylint can be used for. I had a
look at the README and I suppose the intro section at the top could
state the above goal with more clarity.

-- 
Nicolas Chauvat

logilab.fr - services en informatique scientifique et gestion de connaissances  


Reply to: