Skip to content

Clean up mypy & ruff config #30258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions galleries/examples/ticks/date_formatters_locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import matplotlib.pyplot as plt
import numpy as np

# While these appear unused directly, they are used from eval'd strings.
from matplotlib.dates import (FR, MO, MONTHLY, SA, SU, TH, TU, WE,
AutoDateFormatter, AutoDateLocator,
ConciseDateFormatter, DateFormatter, DayLocator,
Expand Down
4 changes: 2 additions & 2 deletions galleries/tutorials/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

In [1]: %matplotlib inline

This turns on inline plotting, where plot graphics will appear in your
notebook. This has important implications for interactivity. For inline plotting, commands in
This turns on inline plotting, where plot graphics will appear in your notebook. This
has important implications for interactivity. For inline plotting, commands in
cells below the cell that outputs a plot will not affect the plot. For example,
changing the colormap is not possible from cells below the cell that creates a plot.
However, for other backends, such as Qt, that open a separate window,
Expand Down
27 changes: 15 additions & 12 deletions lib/matplotlib/backends/web_backend/nbagg_uat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
"metadata": {},
"outputs": [],
"source": [
"from matplotlib.backends.backend_nbagg import new_figure_manager,show\n",
"from matplotlib.backends.backend_nbagg import new_figure_manager\n",
"\n",
"manager = new_figure_manager(1000)\n",
"fig = manager.canvas.figure\n",
Expand Down Expand Up @@ -341,15 +341,18 @@
"x = np.arange(0, 2*np.pi, 0.01) # x-array\n",
"line, = ax.plot(x, np.sin(x))\n",
"\n",
"\n",
"def animate(i):\n",
" line.set_ydata(np.sin(x+i/10.0)) # update the data\n",
" return line,\n",
"\n",
"#Init only required for blitting to give a clean slate.\n",
"\n",
"# Init only required for blitting to give a clean slate.\n",
"def init():\n",
" line.set_ydata(np.ma.array(x, mask=True))\n",
" return line,\n",
"\n",
"\n",
"ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,\n",
" interval=100., blit=True)\n",
"plt.show()"
Expand Down Expand Up @@ -405,6 +408,8 @@
"ln, = ax.plot(x,y)\n",
"evt = []\n",
"colors = iter(itertools.cycle(['r', 'g', 'b', 'k', 'c']))\n",
"\n",
"\n",
"def on_event(event):\n",
" if event.name.startswith('key'):\n",
" fig.suptitle('%s: %s' % (event.name, event.key))\n",
Expand All @@ -417,6 +422,7 @@
" fig.canvas.draw()\n",
" fig.canvas.draw_idle()\n",
"\n",
"\n",
"fig.canvas.mpl_connect('button_press_event', on_event)\n",
"fig.canvas.mpl_connect('button_release_event', on_event)\n",
"fig.canvas.mpl_connect('scroll_event', on_event)\n",
Expand Down Expand Up @@ -448,10 +454,12 @@
"fig, ax = plt.subplots()\n",
"text = ax.text(0.5, 0.5, '', ha='center')\n",
"\n",
"\n",
"def update(text):\n",
" text.set(text=time.ctime())\n",
" text.axes.figure.canvas.draw()\n",
" \n",
"\n",
"\n",
"timer = fig.canvas.new_timer(500, [(update, [text], {})])\n",
"timer.start()\n",
"plt.show()"
Expand All @@ -471,7 +479,7 @@
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"text = ax.text(0.5, 0.5, '', ha='center') \n",
"text = ax.text(0.5, 0.5, '', ha='center')\n",
"timer = fig.canvas.new_timer(500, [(update, [text], {})])\n",
"\n",
"timer.single_shot = True\n",
Expand Down Expand Up @@ -578,18 +586,20 @@
"cnt = itertools.count()\n",
"bg = None\n",
"\n",
"\n",
"def onclick_handle(event):\n",
" \"\"\"Should draw elevating green line on each mouse click\"\"\"\n",
" global bg\n",
" if bg is None:\n",
" bg = ax.figure.canvas.copy_from_bbox(ax.bbox) \n",
" bg = ax.figure.canvas.copy_from_bbox(ax.bbox)\n",
" ax.figure.canvas.restore_region(bg)\n",
"\n",
" cur_y = (next(cnt) % 10) * 0.1\n",
" ln.set_ydata([cur_y, cur_y])\n",
" ax.draw_artist(ln)\n",
" ax.figure.canvas.blit(ax.bbox)\n",
"\n",
"\n",
"fig, ax = plt.subplots()\n",
"ax.plot([0, 1], [0, 1], 'r')\n",
"ln, = ax.plot([0, 1], [0, 0], 'g', animated=True)\n",
Expand All @@ -598,13 +608,6 @@
"\n",
"ax.figure.canvas.mpl_connect('button_press_event', onclick_handle)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
26 changes: 3 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,13 @@ sections = "FUTURE,STDLIB,THIRDPARTY,PYDATA,FIRSTPARTY,LOCALFOLDER"
force_sort_within_sections = true

[tool.ruff]
exclude = [
".git",
extend-exclude = [
"build",
"doc/gallery",
"doc/tutorials",
"tools/gh_api.py",
".tox",
".eggs",
# TODO: fix .ipynb files
"*.ipynb"
]
line-length = 88
target-version = "py311"

[tool.ruff.lint]
ignore = [
Expand All @@ -131,9 +125,7 @@ ignore = [
"D404",
"D413",
"D415",
"D416",
"D417",
"E24",
"E266",
"E305",
"E306",
Expand Down Expand Up @@ -174,15 +166,13 @@ convention = "numpy"

[tool.ruff.lint.per-file-ignores]
"*.pyi" = ["E501"]
"*.ipynb" = ["E402"]
"doc/conf.py" = ["E402"]
"galleries/examples/animation/frame_grabbing_sgskip.py" = ["E402"]
"galleries/examples/images_contours_and_fields/tricontour_demo.py" = ["E201"]
"galleries/examples/images_contours_and_fields/tripcolor_demo.py" = ["E201"]
"galleries/examples/images_contours_and_fields/triplot_demo.py" = ["E201"]
"galleries/examples/lines_bars_and_markers/marker_reference.py" = ["E402"]
"galleries/examples/misc/print_stdout_sgskip.py" = ["E402"]
"galleries/examples/misc/table_demo.py" = ["E201"]
"galleries/examples/style_sheets/bmh.py" = ["E501"]
"galleries/examples/subplots_axes_and_figures/demo_constrained_layout.py" = ["E402"]
"galleries/examples/text_labels_and_annotations/custom_legends.py" = ["E402"]
"galleries/examples/ticks/date_concise_formatter.py" = ["E402"]
Expand Down Expand Up @@ -211,21 +201,17 @@ convention = "numpy"
"lib/mpl_toolkits/axisartist/angle_helper.py" = ["E221"]
"lib/mpl_toolkits/mplot3d/proj3d.py" = ["E201"]

"galleries/users_explain/artists/paths.py" = ["E402"]
"galleries/users_explain/quick_start.py" = ["E402"]
"galleries/users_explain/artists/patheffects_guide.py" = ["E402"]
"galleries/users_explain/artists/transforms_tutorial.py" = ["E402", "E501"]
"galleries/users_explain/colors/colormaps.py" = ["E501"]
"galleries/users_explain/artists/transforms_tutorial.py" = ["E402"]
"galleries/users_explain/colors/colors.py" = ["E402"]
"galleries/tutorials/artists.py" = ["E402"]
"galleries/users_explain/axes/constrainedlayout_guide.py" = ["E402"]
"galleries/users_explain/axes/legend_guide.py" = ["E402"]
"galleries/users_explain/axes/tight_layout_guide.py" = ["E402"]
"galleries/users_explain/animations/animations.py" = ["E501"]
"galleries/tutorials/images.py" = ["E501"]
"galleries/tutorials/pyplot.py" = ["E402", "E501"]
"galleries/users_explain/text/annotations.py" = ["E402", "E501"]
"galleries/users_explain/text/mathtext.py" = ["E501"]
"galleries/users_explain/text/text_intro.py" = ["E402"]
"galleries/users_explain/text/text_props.py" = ["E501"]

Expand All @@ -236,18 +222,12 @@ enable_error_code = [
"redundant-expr",
"truthy-bool",
]
enable_incomplete_feature = [
"Unpack",
]
exclude = [
#stubtest
".*/matplotlib/(sphinxext|backends|pylab|testing/jpl_units)",
#mypy precommit
"galleries/",
"doc/",
"lib/matplotlib/backends/",
"lib/matplotlib/sphinxext",
"lib/matplotlib/testing/jpl_units",
"lib/mpl_toolkits/",
#removing tests causes errors in backends
"lib/matplotlib/tests/",
Expand Down
Loading