Python Code Review Checklist — Python Guidelines 0.1.0 documentation

  • Code is blackened with black

  • flake8 has been run with no errors

  • mypy has been run with no errors

  • Function complexity problems have been resolved using the default
    complexity index of flake8.

  • Important core code can be loaded in iPython, ipdb easily.

  • There is no dead code

  • Comprehensions or generator expressions are used in place of for
    loops where appropriate

  • Comprehensions and generator expressions produce state but they do
    not have side effects within the expression.

  • Use zip(), any(), all(), etc. instead of for loops where
    appropriate

  • Functions that take as parameters and mutate mutable variables don’t
    return these variables. They return None.

  • Return immutable copies of mutable types instead of mutating the
    instances themselves when mutable types are passed as parameters with
    the intention of returning a mutated version of that variable.

  • Avoid method cascading on objects with methods that return self.

  • Function and method parameters never use empty collection or sequence
    instances like list [] or dict {}. Instead they must use
    None to indicate missing input

  • Variables in a function body are initialised with empty sequences or
    collections by callables, list(), dict(), instead of [],
    {}, etc.

  • Always use the Final type hint for class instance parameters that
    will not change.

  • Context-dependent variables are not unnecessarily passed between
    functions or methods

  • View functions either implement the business rules the view is
    repsonsible for or it passes data downstream to have this done by
    services and receives non-context dependent data back.

  • View functions don’t pass request to called functions

  • Functions including class methods don’t have too many local
    parameters or instance variables. Especially a class’ __init__()
    should not have too many parameters.

  • Profiling code is minimal

  • Logging is the minimum required for production use

  • There are no home-brewed solutions for things that already exist in
    the PSL