1 16-TypeFormatDebug

Previous: 15-ClassesInheritance.html

1.1 Screencasts

1.2 Demo a common scenario in the VM

1.2.1 1. Review of code styling and how to auto-style


# Install once.
sudo zypper/dnf/apt install python3-black
# or
pip3 install --upgrade black --user

# Run whenever
black sonar_improved.py
# or
black *.py

+++++++++++ Cahoot-16-1

1.2.2 2. Review of type-hinting and how to auto-hint


# Install once
sudo zypper/dnf/apt install mypy python3-mypy
pip3 install --upgrade monkeytype mypy --user

# Show files above
vim sonar_improved.py sonar_original.py monkey_wrapper.py
monkeytype run monkey_wrapper.py
monkeytype apply sonar_improved.py

1.2.3 3. Interpreters, shebangs, and file permissions


# Install once
sudo zypper/dnf/apt install python3-ipython


# Run whenever
vim sonar_improved.py
# Introduce error?
ipython3 sonar_improved.py
# Fix the error

ll sonar_improved
chmod -x sonar_improved.py
chmod +x sonar_improved.py

# Show the shebang

1.2.4 4. Review of interactive debuggers and how to use them

2 Install once

sudo zypper/dnf/apt install python3-pudb python3-spyder
pip3 install –upgrade pudb spyder –user

3 Run whenever

pudb sonar_improved.py
spyder3 sonar_improved.py &

+++++++++++ Cahoot-16-2

### 5. Review of linting and how to use tips
``` {.sh .numberLines}

# Install once
sudo zypper/dnf/apt install python3-pylint python3-spyder
pip3 install --upgrade pylint spyder --user
# Install linting additions to your favorite text editor (optional)

# Run whenever
pylint sonar_improved.py
vim sonar_improved.py
spyder3 sonar_improved.py &

+++++++++++ Cahoot-16-3

3.0.1 6. Review of diff tools and how to use them


sudo zypper/apt/dnf install meld

man meld
meld --diff sonar_original.py sonar_improved.py

man vimdiff
vim -d sonar_original.py sonar_improved.py

man diff
diff -y --color sonar_original.py sonar_improved.py

git init
git add .
git commit -m "init"
cp sonar_improved.py sonar_original.py
git diff sonar_improved.py

3.0.2 7. Tools to complement documenting your code

Control flow graph: https://en.wikipedia.org/wiki/Control-flow_graph
* py2cfg
* https://py2cfg.readthedocs.io/en/latest/
* https://gitlab.com/classroomcode/py2cfg
* https://pypi.org/project/py2cfg/


pip3 install py2cfg --user

py2cfg sonar_improved.py

Calls: https://en.wikipedia.org/wiki/Call_graph
* pycallgraph
* https://pycallgraph.readthedocs.io/en/master/
* https://pypi.org/project/pycallgraph/
* https://github.com/gak/pycallgraph


pip3 install pycallgraph --user

pycallgraph graphviz sonar_improved.py

UML class diagram: https://en.wikipedia.org/wiki/Class_diagram
* https://pylint.org
* Contains pyreverse
* http://epydoc.sourceforge.net/
* https://modeling-languages.com/uml-tools/#python
* https://sungsoo.github.io/2018/03/21/uml-tools-for-python.html
* https://pynsource.com/


sudo zypper/dnf/apt install python3-pylint
# or
pip3 install pylint --user

pyreverse -o svg somethingwithclasses.py

See 15-ClassesInheritance for examples.

Text documentation generation?
* https://wiki.python.org/moin/DocumentationTools
* https://docs.readthedocs.io/en/stable/intro/getting-started-with-sphinx.html


# TODO sometime later?

Next: 17-Exceptions.html