I’ve written a error-prone program. It contains some unused imported modules, variables and arguments.
It also overriddes one function. I’ve intentionally not followed pep8’s guidelines.
Let’s see output of each linter.
###PyChecker
* It imports each module and compiles the each function, class and method for possible errors.
* It determines the imported modules, classes and functions and creates a tree based on it.
* It can’t process the module if there is an import error.
* It compiles and executes the imported module so your code get executed.
* For example: If you’ve SQL queries in python program then it executes every time which is bad (IMO)
* Let’s pass the sample_program.py and analyze the output.
Here,
It detects following errors:
unused imported module, local variable and arguments errors.
self is argument in function
But it doesn’t detect following errors:
unused global variable user_name.
pep8 related errors (some linters detect it).
It becomes slower than other linters because it imports all the modules and execute it one by one.
You can create configure it by creating configuration file (.pycheckerr)
###PyFlake
* It is a static code analyzer as It identifies errors without executing python code.
* It is faster than PyChecker because it doesn’t import any module and execute it.
* Let’s see output for sample_program.py
Here,
It detects unused imported module, local variable and arguments related errors.
It doesn’t detect following errors:
Unused global variable user_name.
pep8 style guide related error.
Self is used as argument in function
Redefining parameters like int, str which are built-in data type in python
It examines the syntax tree of each file individually So it is faster.
###Flake8
* It is a static code analyzer. Actually it is combination of pep8 and PyFlake.
* It identifies programming errors as well as pep8 style-guide errors.
* Let’s check what it gives on sample_program.py
Here,
It detects following errors:
unused imported module, local variable, arguments error.
pep8 related errors like blank line, too many blank line etc.
It doesn’t detect following errors:
unused global variable user_name.
Self is used as argument in function
Parameters like int, str which are built-in data type in python
###PyLint
* It is a static code analyzer which checks errors in python code.
* It looks for bad codes and tries to enforce a coding standard.
* It displays statistics about the number of warnings and errors found in different files.
* It also gives overall mark, based on numbers of warnings and errors. Some key features as below:
* Refactoring:
* It also detects duplicates codes.
* Fully Customizable:
* You can create your own .pylintrc and modify which errors are important for you.
* UML Diagram:
* It creates UML diagrams for python code using Pyreverse
* Editor and IDE integration:
* Editor Integration are available for various editors like emacs, vim and eclipse
* IDE integration are also available for various IDEs like spyder, editra and TextMate
* Check list of supported editors and IDEs
* It gives very descriptive output. The output is divided into two categories message and reports.
* message contains warnings, errors, coding standard convention, Refactoring and Fatal errors.
* error messages type:
* [R]efactor for a “good practice” metric violation
* [C]onvention for coding standard violation
* [W]arning for stylistic problems, or minor programming issues
* [E]rror for important programming issues (i.e. most probably bug)
* [F]atal for errors which prevented further processing.
* Reports contains statistics information for by type, raw metrics, duplication, message by category etc.
* Let’s run pylint on sample_program.py and check the output.
Here,
It detects highest number of errors compared to other linters.
Following errors which are detected by all other linters as well as PyLint:
unused variables, imported modules, arguments etc.
Invalid variable name, method name etc.
But there is a lot of differnece between Pylint’s output and other’s output.
It detects following errors which other linters don’t detect.:
Unreachable code
Redefining built in int and str
unused global variable user_name which other linters are failed to detect.
missing doc strings.
Report contains various statistics information which is useful for programmer.
It’s awesome code rating. It has given -2.7 rating to sample program. (OMG)
Pylint has great documentation. Every thing is well explained.
You can configure pylint by creating configuration file i.e .pylintrc file.
###PyLama
* It is a static code analyzer which combines power of other linters.
* It wrapes following tools:
* PEP8
* PEP257
* PyFlakes
* Mccabe
* PyLint
* Let’s check it’s output
Here,
It detects following errors:
unused variable, imported module and argument errors.
redefinition of function.
pep8 errors
It doesn’t detect following errors:
unreachable code
missing doc string
Self is used as argument in function
redefining built-in datatype like int, str etc.
invalid function name like getUserPassword etc.
Conclusion:
Most of these tools detect some of the errors in sample_program.py. We saw all tools output for sample_program.py
PyLint gives us very descriptive output as well as detects various errors.
So we can deduce that Pylint’s is a very powerful linters for python programming.