Without compilation, how to find bugs?

Skip Montanaro skip.montanaro at gmail.com
Thu Oct 13 19:34:39 EDT 2016


> I can execute the script without any problem and I will not notice the
bug until I
> test exactly the erroneous line of code (the call with only one argument).

The key phrase there being "until I test..." <wink> There are static
analysis tools for Python like pylint. Given this simple module:

#!/usr/bin/env python

def func2(a, b):
    print(a, b)

def func1(a):
    print(a)

func2(1)

among other messages, pylint prints:

E:  9, 0: No value for argument 'b' in function call
(no-value-for-parameter)

where line 9 is the erroneous call to func2().

Static analysis tools like pylint aren't perfect, but do catch a bunch of
stuff. Also, given the run-time detection of errors, in dynamic languages
like Python, unit tests and code coverage are particularly important. Also,
check out type hints, mypy, and the typeshed project:

https://www.python.org/dev/peps/pep-0484/
http://mypy-lang.org/
https://github.com/python/typeshed

Skip



More information about the Python-list mailing list