System Development with Python

Week 2 :: PEP-8 / analysis tools

Adapted from Joseph Sheedy's and Chris Barker's materials

PEP-8

Style Guide for Python

Defines a good baseline for your own local style guide

The 'rules' are just suggestions. From the document:

most importantly: know when to be inconsistent -- sometimes the style guide just doesn't apply

Important PEP-8 recommendations

PEP-8 recommendations (continued)

PEP-8 recommendations (continued)

Naming conventions

Argument conventions

PEP-8 recommendations (continued)

Imports

PEP-8 recommendations (continued)

public and non-public class members

Tools to help

pyflakes

Doesn't check style, just checks for functional errors

Similar to pychecker, but does not execute code

Now let's see what pyflakes Listing1.py has to say

What's the overlap in pyflakes' output versus the other two tools?

pep8

Only checks style

Interesting options:


--statistics         count errors and warnings
--count              print total number of errors and warnings to standard error and set exit code to 1 if total is not null

Now let's see what pep8 Listing1.py has to say

What's the overlap in pep8's output versus the other two tools?

flake8

A tool which wraps pep8, pyflakes, and mccabe

mccabe is a "microtool" written by Ned Batchelder (author of coverage) for assessing Cyclomatic Complexity

Interesting options:


--max-complexity=N    McCabe complexity threshold
        

Now let's see what flake8 Listing1.py has to say

What's the overlap in flake8 output versus the other two tools?

flake8...demo

Where can I look up error codes?

Flake8 ReadTheDocs

What is cyclomatic complexity and how can i reason about it?

Good Overview
1 + ifs + loops + switch cases

analysis tool summary

/