Lint fixes on benchmarks and examples/*.py by roryyorke · Pull Request #1135 · python-control/python-control
I don't think these are too controversial.
CI failures
I see two failures on CI , but I can't see that these changes caused them:
first, in doctest-linux: https://github.com/roryyorke/python-control/actions/runs/13612156165/job/38050709282
Traceback
=========
File "/home/runner/miniconda3/envs/doctest-env/lib/python3.12/site-packages/sphinx/events.py", line 415, in emit
raise ExtensionError(
sphinx.errors.ExtensionError: Handler <function html_collect_pages at 0x7f36a35016c0> for event 'html-collect-pages' threw an exception (exception: module 'sphinx.util' has no attribute 'console')
which seems to be sphinx-doc/sphinx#13352.
Then in install-examples: https://github.com/roryyorke/python-control/actions/runs/13612156159/job/38050709274
ModuleNotFoundError: No module named 'autoreload'
I'll install jupyterlab in my dev environment and see if I can reproduce this. I can't see that changing *.py files in examples could cause this.
tfvis.py and Pwm Pmw
When I ran tfvis.py under Python 3.12, I got
AttributeError: module 'collections' has no attribute 'Callable'
in Pwm Pmw code.
Callable was moved to collections.abc in Python 3.10 (October 2021). The hack below lets the script run, but unless pwm Pmw is updated we should consider retiring this example.
modified examples/tfvis.py @@ -48,6 +48,9 @@ from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg from control.matlab import logspace from numpy import array, conj, polymul, real, size +import collections.abc +collections.Callable = collections.abc.Callable + def make_poly(facts): """ Create polynomial from factors """
Warnings in examples
Some examples raise control deprecation warnings, e.g., genswitch.py uses phase_plot instead of phase_plane_plot. I started looking into this, but it got a bit involved.
Lint on notebooks
ruff can also run on Jupyter notebooks. Some fixes are obvious:
examples/bode-and-nyquist-plots.ipynb:cell 2:2:17: F401 [*] `scipy` imported but unused
|
1 | import numpy as np
2 | import scipy as sp
| ^^ F401
3 | import matplotlib.pyplot as plt
4 | import control as ct
|
= help: Remove unused import: `scipy`
but I'm less sure about changing these * imports; they are convenient, and make things more familiar for Matlab users:
examples/pvtol-lqr-nested.ipynb:cell 3:2:1: F403 `from matplotlib.pyplot import *` used; unable to detect undefined names
|
1 | from numpy import * # Grab all of the NumPy functions
2 | from matplotlib.pyplot import * # Grab MATLAB plotting functions
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F403
3 | from control.matlab import * # MATLAB-like functions
4 | %matplotlib inline
|