Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9c69c32

Browse files
authored
Merge pull request #28593 from QuLogic/ruff-update
Update ruff to 0.2.0
2 parents e6f2b0c + 9d6e216 commit 9c69c32

22 files changed

+90
-78
lines changed

.flake8

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,18 @@ exclude =
3434

3535
per-file-ignores =
3636
lib/matplotlib/_cm.py: E202, E203, E302
37-
lib/matplotlib/_mathtext.py: E221, E251
38-
lib/matplotlib/_mathtext_data.py: E203, E261
37+
lib/matplotlib/_mathtext.py: E221
38+
lib/matplotlib/_mathtext_data.py: E203
3939
lib/matplotlib/backends/backend_template.py: F401
4040
lib/matplotlib/mathtext.py: E221
4141
lib/matplotlib/pylab.py: F401, F403
4242
lib/matplotlib/pyplot.py: F811
4343
lib/matplotlib/tests/test_mathtext.py: E501
44-
lib/matplotlib/transforms.py: E201, E202, E203
44+
lib/matplotlib/transforms.py: E201, E202
4545
lib/matplotlib/tri/_triinterpolate.py: E201, E221
4646
lib/mpl_toolkits/axes_grid1/axes_size.py: E272
4747
lib/mpl_toolkits/axisartist/angle_helper.py: E221
48+
lib/mpl_toolkits/mplot3d/proj3d.py: E201
4849

4950
doc/conf.py: E402
5051
galleries/users_explain/quick_start.py: E402

lib/matplotlib/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,5 @@ def _preprocess_data(
111111
label_namer: str | None = ...
112112
) -> Callable: ...
113113

114-
from matplotlib.cm import _colormaps as colormaps
115-
from matplotlib.colors import _color_sequences as color_sequences
114+
from matplotlib.cm import _colormaps as colormaps # noqa: E402
115+
from matplotlib.colors import _color_sequences as color_sequences # noqa: E402

lib/matplotlib/_api/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from typing_extensions import Self # < Py 3.11
44

55
from numpy.typing import NDArray
66

7-
from .deprecation import ( # noqa: re-exported API
7+
from .deprecation import ( # noqa: F401, re-exported API
88
deprecated as deprecated,
99
warn_deprecated as warn_deprecated,
1010
rename_parameter as rename_parameter,

lib/matplotlib/_mathtext.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -379,27 +379,27 @@ def _get_info(self, fontname: str, font_class: str, sym: str, fontsize: float,
379379
xmin, ymin, xmax, ymax = [val/64.0 for val in glyph.bbox]
380380
offset = self._get_offset(font, glyph, fontsize, dpi)
381381
metrics = FontMetrics(
382-
advance = glyph.linearHoriAdvance/65536.0,
383-
height = glyph.height/64.0,
384-
width = glyph.width/64.0,
385-
xmin = xmin,
386-
xmax = xmax,
387-
ymin = ymin+offset,
388-
ymax = ymax+offset,
382+
advance=glyph.linearHoriAdvance / 65536,
383+
height=glyph.height / 64,
384+
width=glyph.width / 64,
385+
xmin=xmin,
386+
xmax=xmax,
387+
ymin=ymin + offset,
388+
ymax=ymax + offset,
389389
# iceberg is the equivalent of TeX's "height"
390-
iceberg = glyph.horiBearingY/64.0 + offset,
391-
slanted = slanted
392-
)
390+
iceberg=glyph.horiBearingY / 64 + offset,
391+
slanted=slanted
392+
)
393393

394394
return FontInfo(
395-
font = font,
396-
fontsize = fontsize,
397-
postscript_name = font.postscript_name,
398-
metrics = metrics,
399-
num = num,
400-
glyph = glyph,
401-
offset = offset
402-
)
395+
font=font,
396+
fontsize=fontsize,
397+
postscript_name=font.postscript_name,
398+
metrics=metrics,
399+
num=num,
400+
glyph=glyph,
401+
offset=offset
402+
)
403403

404404
def get_xheight(self, fontname: str, fontsize: float, dpi: float) -> float:
405405
font = self._get_font(fontname)

lib/matplotlib/axes/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from . import _base
2-
from ._axes import Axes # noqa: F401
2+
from ._axes import Axes
33

44
# Backcompat.
55
Subplot = Axes

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import matplotlib.collections as mcoll
1515
import matplotlib.colors as mcolors
1616
import matplotlib.contour as mcontour
17-
import matplotlib.dates # noqa # Register date unit converter as side effect.
17+
import matplotlib.dates # noqa: F401, Register date unit converter as side effect.
1818
import matplotlib.image as mimage
1919
import matplotlib.legend as mlegend
2020
import matplotlib.lines as mlines

lib/matplotlib/axes/_axes.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class Axes(_AxesBase):
202202
*args: float | ArrayLike | str,
203203
scalex: bool = ...,
204204
scaley: bool = ...,
205-
data = ...,
205+
data=...,
206206
**kwargs
207207
) -> list[Line2D]: ...
208208
def plot_date(
@@ -232,7 +232,7 @@ class Axes(_AxesBase):
232232
detrend: Callable[[ArrayLike], ArrayLike] = ...,
233233
usevlines: bool = ...,
234234
maxlags: int = ...,
235-
data = ...,
235+
data=...,
236236
**kwargs
237237
) -> tuple[np.ndarray, np.ndarray, LineCollection | Line2D, Line2D | None]: ...
238238
def step(
@@ -241,7 +241,7 @@ class Axes(_AxesBase):
241241
y: ArrayLike,
242242
*args,
243243
where: Literal["pre", "post", "mid"] = ...,
244-
data = ...,
244+
data=...,
245245
**kwargs
246246
) -> list[Line2D]: ...
247247
def bar(
@@ -252,7 +252,7 @@ class Axes(_AxesBase):
252252
bottom: float | ArrayLike | None = ...,
253253
*,
254254
align: Literal["center", "edge"] = ...,
255-
data = ...,
255+
data=...,
256256
**kwargs
257257
) -> BarContainer: ...
258258
def barh(
@@ -263,7 +263,7 @@ class Axes(_AxesBase):
263263
left: float | ArrayLike | None = ...,
264264
*,
265265
align: Literal["center", "edge"] = ...,
266-
data = ...,
266+
data=...,
267267
**kwargs
268268
) -> BarContainer: ...
269269
def bar_label(

lib/matplotlib/backends/qt_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
if QT_API_ENV in ["pyqt5", "pyside2"]:
5050
QT_API = _ETS[QT_API_ENV]
5151
else:
52-
_QT_FORCE_QT5_BINDING = True # noqa
52+
_QT_FORCE_QT5_BINDING = True # noqa: F811
5353
QT_API = None
5454
# A non-Qt backend was selected but we still got there (possible, e.g., when
5555
# fully manually embedding Matplotlib in a Qt app without using pyplot).

lib/matplotlib/contour.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ from matplotlib.artist import Artist
33
from matplotlib.axes import Axes
44
from matplotlib.collections import Collection, PathCollection
55
from matplotlib.colors import Colormap, Normalize
6-
from matplotlib.font_manager import FontProperties
76
from matplotlib.path import Path
87
from matplotlib.patches import Patch
98
from matplotlib.text import Text

lib/matplotlib/gridspec.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from typing import Any, Literal, overload
33
from numpy.typing import ArrayLike
44
import numpy as np
55

6-
from matplotlib.axes import Axes, SubplotBase
6+
from matplotlib.axes import Axes
77
from matplotlib.backend_bases import RendererBase
88
from matplotlib.figure import Figure
99
from matplotlib.transforms import Bbox

lib/matplotlib/lines.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from .artist import Artist
22
from .axes import Axes
33
from .backend_bases import MouseEvent, FigureCanvasBase
44
from .path import Path
5-
from .transforms import Bbox, Transform
5+
from .transforms import Bbox
66

77
from collections.abc import Callable, Sequence
88
from typing import Any, Literal, overload

lib/matplotlib/mathtext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from matplotlib import _api, _mathtext
2323
from matplotlib.ft2font import LOAD_NO_HINTING
2424
from matplotlib.font_manager import FontProperties
25-
from ._mathtext import ( # noqa: reexported API
25+
from ._mathtext import ( # noqa: F401, reexported API
2626
RasterParse, VectorParse, get_unicode_index)
2727

2828
_log = logging.getLogger(__name__)

lib/matplotlib/pyplot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@
5555
import matplotlib.colorbar
5656
import matplotlib.image
5757
from matplotlib import _api
58-
from matplotlib import ( # noqa: F401 Re-exported for typing.
59-
cm as cm, get_backend as get_backend, rcParams as rcParams, style as style)
58+
# Re-exported (import x as x) for typing.
59+
from matplotlib import cm as cm, get_backend as get_backend, rcParams as rcParams
60+
from matplotlib import style as style # noqa: F401
6061
from matplotlib import _pylab_helpers
6162
from matplotlib import interactive # noqa: F401
6263
from matplotlib import cbook
@@ -4017,7 +4018,7 @@ def spy(
40174018
**kwargs,
40184019
)
40194020
if isinstance(__ret, cm.ScalarMappable):
4020-
sci(__ret) # noqa
4021+
sci(__ret)
40214022
return __ret
40224023

40234024

lib/matplotlib/spines.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Callable, Iterator, MutableMapping
2-
from typing import Any, Literal, TypeVar, overload
2+
from typing import Literal, TypeVar, overload
33

44
import matplotlib.patches as mpatches
55
from matplotlib.axes import Axes

lib/matplotlib/tests/test_ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ def test_subs(self):
637637
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1, subs=[2.0, 4.0])
638638
sym.create_dummy_axis()
639639
sym.axis.set_view_interval(-10, 10)
640-
assert (sym() == [-20., -40., -2., -4., 0., 2., 4., 20., 40.]).all()
640+
assert_array_equal(sym(), [-20, -40, -2, -4, 0, 2, 4, 20, 40])
641641

642642
def test_extending(self):
643643
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1)

lib/matplotlib/tests/test_triangulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ def test_tricontourf_decreasing_levels():
11831183

11841184
def test_internal_cpp_api():
11851185
# Following github issue 8197.
1186-
from matplotlib import _tri # noqa: ensure lazy-loaded module *is* loaded.
1186+
from matplotlib import _tri # noqa: F401, ensure lazy-loaded module *is* loaded.
11871187

11881188
# C++ Triangulation.
11891189
with pytest.raises(

lib/matplotlib/text.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from .font_manager import FontProperties
44
from .offsetbox import DraggableAnnotation
55
from .path import Path
66
from .patches import FancyArrowPatch, FancyBboxPatch
7-
from .textpath import ( # noqa: reexported API
7+
from .textpath import ( # noqa: F401, reexported API
88
TextPath as TextPath,
99
TextToPath as TextToPath,
1010
)

lib/matplotlib/transforms.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,9 +2574,9 @@ def get_matrix(self):
25742574
if DEBUG and (x_scale == 0 or y_scale == 0):
25752575
raise ValueError(
25762576
"Transforming from or to a singular bounding box")
2577-
self._mtx = np.array([[x_scale, 0.0 , (-inl*x_scale+outl)],
2578-
[0.0 , y_scale, (-inb*y_scale+outb)],
2579-
[0.0 , 0.0 , 1.0 ]],
2577+
self._mtx = np.array([[x_scale, 0.0, -inl*x_scale+outl],
2578+
[ 0.0, y_scale, -inb*y_scale+outb],
2579+
[ 0.0, 0.0, 1.0]],
25802580
float)
25812581
self._inverted = None
25822582
self._invalid = 0
@@ -2668,9 +2668,9 @@ def get_matrix(self):
26682668
raise ValueError("Transforming from a singular bounding box.")
26692669
x_scale = 1.0 / inw
26702670
y_scale = 1.0 / inh
2671-
self._mtx = np.array([[x_scale, 0.0 , (-inl*x_scale)],
2672-
[0.0 , y_scale, (-inb*y_scale)],
2673-
[0.0 , 0.0 , 1.0 ]],
2671+
self._mtx = np.array([[x_scale, 0.0, -inl*x_scale],
2672+
[ 0.0, y_scale, -inb*y_scale],
2673+
[ 0.0, 0.0, 1.0]],
26742674
float)
26752675
self._inverted = None
26762676
self._invalid = 0

lib/matplotlib/widgets.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from .backend_bases import FigureCanvasBase, Event, MouseEvent, MouseButton
44
from .collections import LineCollection
55
from .figure import Figure
66
from .lines import Line2D
7-
from .patches import Circle, Polygon, Rectangle
7+
from .patches import Polygon, Rectangle
88
from .text import Text
99

1010
import PIL.Image

lib/mpl_toolkits/mplot3d/proj3d.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ def world_transformation(xmin, xmax,
2323
dy /= ay
2424
dz /= az
2525

26-
return np.array([[1/dx, 0, 0, -xmin/dx],
27-
[0, 1/dy, 0, -ymin/dy],
28-
[0, 0, 1/dz, -zmin/dz],
29-
[0, 0, 0, 1]])
26+
return np.array([[1/dx, 0, 0, -xmin/dx],
27+
[ 0, 1/dy, 0, -ymin/dy],
28+
[ 0, 0, 1/dz, -zmin/dz],
29+
[ 0, 0, 0, 1]])
3030

3131

3232
@_api.deprecated("3.8")

pyproject.toml

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ exclude = [
112112
".tox",
113113
".eggs",
114114
]
115+
line-length = 88
116+
target-version = "py310"
117+
118+
[tool.ruff.lint]
115119
ignore = [
116120
"D100",
117121
"D101",
@@ -132,42 +136,46 @@ ignore = [
132136
"E741",
133137
"F841",
134138
]
135-
line-length = 88
139+
preview = true
140+
explicit-preview-rules = true
136141
select = [
137142
"D",
138143
"E",
139144
"F",
140145
"W",
146+
# The following error codes require the preview mode to be enabled.
147+
"E201",
148+
"E202",
149+
"E203",
150+
"E221",
151+
"E251",
152+
"E261",
153+
"E272",
154+
"E703",
141155
]
142156

143-
# The following error codes are not supported by ruff v0.0.240
157+
# The following error codes are not supported by ruff v0.2.0
144158
# They are planned and should be selected once implemented
145159
# even if they are deselected by default.
146160
# These are primarily whitespace/corrected by autoformatters (which we don't use).
147161
# See https://github.com/charliermarsh/ruff/issues/2402 for status on implementation
148162
external = [
149163
"E122",
150-
"E201",
151-
"E202",
152-
"E203",
153-
"E221",
154-
"E251",
155-
"E261",
156-
"E272",
157164
"E302",
158-
"E703",
159165
]
160166

161-
target-version = "py310"
162-
163-
[tool.ruff.pydocstyle]
167+
[tool.ruff.lint.pydocstyle]
164168
convention = "numpy"
165169

166-
[tool.ruff.per-file-ignores]
170+
[tool.ruff.lint.per-file-ignores]
167171
"doc/conf.py" = ["E402"]
168172
"galleries/examples/animation/frame_grabbing_sgskip.py" = ["E402"]
173+
"galleries/examples/images_contours_and_fields/tricontour_demo.py" = ["E201"]
174+
"galleries/examples/images_contours_and_fields/tripcolor_demo.py" = ["E201"]
175+
"galleries/examples/images_contours_and_fields/triplot_demo.py" = ["E201"]
169176
"galleries/examples/lines_bars_and_markers/marker_reference.py" = ["E402"]
170177
"galleries/examples/misc/print_stdout_sgskip.py" = ["E402"]
178+
"galleries/examples/misc/table_demo.py" = ["E201"]
171179
"galleries/examples/style_sheets/bmh.py" = ["E501"]
172180
"galleries/examples/subplots_axes_and_figures/demo_constrained_layout.py" = ["E402"]
173181
"galleries/examples/text_labels_and_annotations/custom_legends.py" = ["E402"]
@@ -184,18 +192,18 @@ convention = "numpy"
184192
"galleries/examples/user_interfaces/pylab_with_gtk4_sgskip.py" = ["E402"]
185193
"galleries/examples/userdemo/pgf_preamble_sgskip.py" = ["E402"]
186194

187-
"lib/matplotlib/__init__.py" = ["E402", "F401"]
188-
"lib/matplotlib/_animation_data.py" = ["E501"]
189-
"lib/matplotlib/_api/__init__.py" = ["F401"]
190-
"lib/matplotlib/axes/__init__.py" = ["F401", "F403"]
195+
"lib/matplotlib/_cm.py" = ["E202", "E203"]
196+
"lib/matplotlib/_mathtext.py" = ["E221"]
197+
"lib/matplotlib/_mathtext_data.py" = ["E203"]
191198
"lib/matplotlib/backends/backend_template.py" = ["F401"]
192-
"lib/matplotlib/font_manager.py" = ["E501"]
193-
"lib/matplotlib/image.py" = ["F401", "F403"]
194199
"lib/matplotlib/pylab.py" = ["F401", "F403"]
195-
"lib/matplotlib/pyplot.py" = ["F401", "F811"]
200+
"lib/matplotlib/pyplot.py" = ["F811"]
196201
"lib/matplotlib/tests/test_mathtext.py" = ["E501"]
197-
"lib/mpl_toolkits/axisartist/__init__.py" = ["F401"]
198-
"lib/pylab.py" = ["F401", "F403"]
202+
"lib/matplotlib/transforms.py" = ["E201"]
203+
"lib/matplotlib/tri/_triinterpolate.py" = ["E201", "E221"]
204+
"lib/mpl_toolkits/axes_grid1/axes_size.py" = ["E272"]
205+
"lib/mpl_toolkits/axisartist/angle_helper.py" = ["E221"]
206+
"lib/mpl_toolkits/mplot3d/proj3d.py" = ["E201"]
199207

200208
"galleries/users_explain/artists/paths.py" = ["E402"]
201209
"galleries/users_explain/artists/patheffects_guide.py" = ["E402"]

0 commit comments

Comments
 (0)