Skip to content

Commit ebdda15

Browse files
Merge pull request #747 from jarrodmillman/ruff-config
Update ruff config
2 parents 93e82fd + 3c9c0fb commit ebdda15

File tree

9 files changed

+58
-24
lines changed

9 files changed

+58
-24
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ bb473f6ff4a23e4fd5205eacdef713db15decadf
55
67c4efab4e3ec1dc16c18b9ab8c5cd5f375040e0
66
8d00b416689c428b2bafdaad61ed3ec660ca06c2
77
d6b447cab8c40aa47dc675a0f4349ae254e8b3ce
8+
d8966d848af75751823e825eb76c5bbff58f5c07

advanced/mathematical_optimization/examples/plot_compare_optimizers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
method_names.sort(key=lambda x: x[::-1], reverse=True)
3030

3131
for n_dim_index, ((n_dim, n_dim_bench), color) in enumerate(
32-
zip(sorted(results.items()), colors)
32+
zip(sorted(results.items()), colors, strict=True)
3333
):
34-
for (cost_name, cost_bench), symbol in zip(sorted(n_dim_bench.items()), symbols):
34+
for (cost_name, cost_bench), symbol in zip(
35+
sorted(n_dim_bench.items()), symbols, strict=True
36+
):
3537
for (
3638
method_index,
3739
method_name,
@@ -50,7 +52,7 @@
5052
)
5153

5254
# Create a legend for the problem type
53-
for cost_name, symbol in zip(sorted(n_dim_bench.keys()), symbols):
55+
for cost_name, symbol in zip(sorted(n_dim_bench.keys()), symbols, strict=True):
5456
plt.semilogy(
5557
[
5658
-10,
@@ -71,7 +73,7 @@
7173
# Create a second legend for the problem dimensionality
7274
plt.twinx()
7375

74-
for n_dim, color in zip(sorted(results.keys()), colors):
76+
for n_dim, color in zip(sorted(results.keys()), colors, strict=True):
7577
plt.plot(
7678
[
7779
-10,

advanced/mathematical_optimization/examples/plot_gradient_descent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import matplotlib.pyplot as plt
1111
import scipy as sp
1212

13-
import sys, os
13+
import sys
14+
import os
1415

1516
sys.path.append(os.path.abspath("helper"))
1617
from cost_functions import (
@@ -245,7 +246,7 @@ def store(X):
245246
)
246247
contours = plt.contour(
247248
log_z,
248-
levels=levels.get(f, None),
249+
levels=levels.get(f),
249250
extent=[x_min, x_max, y_min, y_max],
250251
cmap=plt.cm.gnuplot,
251252
origin="lower",

intro/matplotlib/examples/plot_bar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
plt.bar(X, +Y1, facecolor="#9999ff", edgecolor="white")
1919
plt.bar(X, -Y2, facecolor="#ff9999", edgecolor="white")
2020

21-
for x, y in zip(X, Y1):
21+
for x, y in zip(X, Y1, strict=True):
2222
plt.text(x + 0.4, y + 0.05, f"{y:.2f}", ha="center", va="bottom")
2323

24-
for x, y in zip(X, Y2):
24+
for x, y in zip(X, Y2, strict=True):
2525
plt.text(x + 0.4, -y - 0.05, f"{y:.2f}", ha="center", va="top")
2626

2727
plt.xlim(-0.5, n)

intro/matplotlib/examples/plot_polar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
width = np.pi / 4 * rng.random(N)
1919
bars = plt.bar(theta, radii, width=width, bottom=0.0)
2020

21-
for r, bar in zip(radii, bars):
21+
for r, bar in zip(radii, bars, strict=True):
2222
bar.set_facecolor(plt.cm.jet(r / 10.0))
2323
bar.set_alpha(0.5)
2424

intro/matplotlib/examples/pretty_plots/plot_polar_ext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
radii = 10 * rng.random(N)
1818
width = np.pi / 4 * rng.random(N)
1919
bars = plt.bar(theta, radii, width=width, bottom=0.0)
20-
for r, bar in zip(radii, bars):
20+
for r, bar in zip(radii, bars, strict=True):
2121
bar.set_facecolor(plt.cm.jet(r / 10.0))
2222
bar.set_alpha(0.5)
2323
plt.gca().set_xticklabels([])

packages/scikit-learn/examples/plot_pca.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import matplotlib.pyplot as plt
3232

3333
plt.figure(figsize=(6, 5))
34-
for i, c, label in zip(target_ids, "rgbcmykw", iris.target_names):
34+
for i, c, label in zip(target_ids, "rgbcmykw", iris.target_names, strict=False):
3535
plt.scatter(X_pca[y == i, 0], X_pca[y == i, 1], c=c, label=label)
3636
plt.legend()
3737
plt.show()

packages/scikit-learn/examples/plot_tsne.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
plt.figure(figsize=(6, 5))
4040
colors = "r", "g", "b", "c", "m", "y", "k", "w", "orange", "purple"
41-
for i, c, label in zip(target_ids, colors, digits.target_names):
41+
for i, c, label in zip(target_ids, colors, digits.target_names, strict=True):
4242
plt.scatter(X_2d[y == i, 0], X_2d[y == i, 1], c=c, label=label)
4343
plt.legend()
4444
plt.show()

ruff.toml

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,48 @@ target-version = "py310"
22

33
[lint]
44
select = [
5-
"UP", # pyupgrade
6-
"C4", # flake8-comprehensions
7-
"E713", # use 'key not in list'
8-
"NPY201", # NumPy 2 compatibility
9-
"PIE", # flake8-pie
10-
"PGH003", # forbid blanket 'type: ignore' comments
11-
"PLR0402", # useless import alias
12-
"SIM101", # merge 'isinstance' calls
13-
"SIM109", # use a tuple for multiple comparisons
14-
"SIM110", # convert loop to 'any'
15-
"SIM118", # use 'key in dict'
16-
"SIM2", # simplify boolean comparisons
5+
"B", # flake8-bugbear
6+
"C4", # flake8-comprehensions
7+
"E", # pycodestyle-error
8+
"EM", # flake8-errmsg
9+
"EXE", # flake8-executable
10+
"FURB", # refurb
11+
"NPY", # NumPy specific rules
12+
"PD", # pandas-vet
13+
"PGH", # pygrep-hooks
14+
"PIE", # flake8-pie
15+
"PL", # pylint
16+
# "PTH", # flake8-use-pathlib
17+
"PYI", # flake8-pyi
18+
# "RET", # flake8-return
19+
"RUF", # ruff-specific
20+
"SIM", # flake8-simplify
21+
"SIM2", # simplify boolean comparisons
22+
"UP", # pyupgrade
23+
"YTT" # flake8-2020
24+
]
25+
ignore = [
26+
"B006", # Do not use mutable data structures for argument defaults
27+
"B007", # Loop control variable {name} not used within loop body
28+
"B018", # Found useless expression. Either assign it to a variable or remove it.
29+
"E402", # Module level import not at top of file
30+
"E501", # Line too long
31+
"E741", # Ambiguous variable name
32+
"E721", # Do not compare types, use `isinstance()`
33+
"E731", # Do not assign a `lambda` expression, use a `def`
34+
"EM101", # Exception must not use a string literal, assign to variable first
35+
"EM102", # Exception must not use an f-string literal, assign to variable first
36+
"ISC001", # Conflicts with formatter
37+
"NPY002", # Replace legacy np.random.{method_name} call with np.random.Generator
38+
"PD002", # inplace=True should be avoided; it has inconsistent behavior
39+
"PLR", # pylint-refactor
40+
"PLR09", # Too many <...>
41+
"PLR2004", # Magic value used in comparison
42+
"PLW0127", # Self-assignment of variable {name}
43+
"PLW2901", # Outer {outer_kind} variable {name} overwritten by inner {inner_kind} target
44+
"RUF005", # Consider {expression} instead of concatenation
45+
"RUF015", # Prefer next({iterable}) over single element slice
46+
"SIM115" # Use context handler for opening files
1747
]
1848

1949
[format]

0 commit comments

Comments
 (0)