diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 7ad2a6935..266d91be4 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -5,3 +5,4 @@ bb473f6ff4a23e4fd5205eacdef713db15decadf 67c4efab4e3ec1dc16c18b9ab8c5cd5f375040e0 8d00b416689c428b2bafdaad61ed3ec660ca06c2 d6b447cab8c40aa47dc675a0f4349ae254e8b3ce +d8966d848af75751823e825eb76c5bbff58f5c07 diff --git a/advanced/mathematical_optimization/examples/plot_compare_optimizers.py b/advanced/mathematical_optimization/examples/plot_compare_optimizers.py index ebcb8895c..2e75f75f8 100644 --- a/advanced/mathematical_optimization/examples/plot_compare_optimizers.py +++ b/advanced/mathematical_optimization/examples/plot_compare_optimizers.py @@ -29,9 +29,11 @@ method_names.sort(key=lambda x: x[::-1], reverse=True) for n_dim_index, ((n_dim, n_dim_bench), color) in enumerate( - zip(sorted(results.items()), colors) + zip(sorted(results.items()), colors, strict=True) ): - for (cost_name, cost_bench), symbol in zip(sorted(n_dim_bench.items()), symbols): + for (cost_name, cost_bench), symbol in zip( + sorted(n_dim_bench.items()), symbols, strict=True + ): for ( method_index, method_name, @@ -50,7 +52,7 @@ ) # Create a legend for the problem type -for cost_name, symbol in zip(sorted(n_dim_bench.keys()), symbols): +for cost_name, symbol in zip(sorted(n_dim_bench.keys()), symbols, strict=True): plt.semilogy( [ -10, @@ -71,7 +73,7 @@ # Create a second legend for the problem dimensionality plt.twinx() -for n_dim, color in zip(sorted(results.keys()), colors): +for n_dim, color in zip(sorted(results.keys()), colors, strict=True): plt.plot( [ -10, diff --git a/advanced/mathematical_optimization/examples/plot_gradient_descent.py b/advanced/mathematical_optimization/examples/plot_gradient_descent.py index 47453246a..812215b9a 100644 --- a/advanced/mathematical_optimization/examples/plot_gradient_descent.py +++ b/advanced/mathematical_optimization/examples/plot_gradient_descent.py @@ -10,7 +10,8 @@ import matplotlib.pyplot as plt import scipy as sp -import sys, os +import sys +import os sys.path.append(os.path.abspath("helper")) from cost_functions import ( @@ -245,7 +246,7 @@ def store(X): ) contours = plt.contour( log_z, - levels=levels.get(f, None), + levels=levels.get(f), extent=[x_min, x_max, y_min, y_max], cmap=plt.cm.gnuplot, origin="lower", diff --git a/intro/matplotlib/examples/plot_bar.py b/intro/matplotlib/examples/plot_bar.py index fe79ba03b..c1ff47a15 100644 --- a/intro/matplotlib/examples/plot_bar.py +++ b/intro/matplotlib/examples/plot_bar.py @@ -18,10 +18,10 @@ plt.bar(X, +Y1, facecolor="#9999ff", edgecolor="white") plt.bar(X, -Y2, facecolor="#ff9999", edgecolor="white") -for x, y in zip(X, Y1): +for x, y in zip(X, Y1, strict=True): plt.text(x + 0.4, y + 0.05, f"{y:.2f}", ha="center", va="bottom") -for x, y in zip(X, Y2): +for x, y in zip(X, Y2, strict=True): plt.text(x + 0.4, -y - 0.05, f"{y:.2f}", ha="center", va="top") plt.xlim(-0.5, n) diff --git a/intro/matplotlib/examples/plot_polar.py b/intro/matplotlib/examples/plot_polar.py index a6ac442dd..b610e962c 100644 --- a/intro/matplotlib/examples/plot_polar.py +++ b/intro/matplotlib/examples/plot_polar.py @@ -18,7 +18,7 @@ width = np.pi / 4 * rng.random(N) bars = plt.bar(theta, radii, width=width, bottom=0.0) -for r, bar in zip(radii, bars): +for r, bar in zip(radii, bars, strict=True): bar.set_facecolor(plt.cm.jet(r / 10.0)) bar.set_alpha(0.5) diff --git a/intro/matplotlib/examples/pretty_plots/plot_polar_ext.py b/intro/matplotlib/examples/pretty_plots/plot_polar_ext.py index 1c7f88a56..7d5765b64 100644 --- a/intro/matplotlib/examples/pretty_plots/plot_polar_ext.py +++ b/intro/matplotlib/examples/pretty_plots/plot_polar_ext.py @@ -17,7 +17,7 @@ radii = 10 * rng.random(N) width = np.pi / 4 * rng.random(N) bars = plt.bar(theta, radii, width=width, bottom=0.0) -for r, bar in zip(radii, bars): +for r, bar in zip(radii, bars, strict=True): bar.set_facecolor(plt.cm.jet(r / 10.0)) bar.set_alpha(0.5) plt.gca().set_xticklabels([]) diff --git a/packages/scikit-learn/examples/plot_pca.py b/packages/scikit-learn/examples/plot_pca.py index 8c8127d1c..e09f420e4 100644 --- a/packages/scikit-learn/examples/plot_pca.py +++ b/packages/scikit-learn/examples/plot_pca.py @@ -31,7 +31,7 @@ import matplotlib.pyplot as plt plt.figure(figsize=(6, 5)) -for i, c, label in zip(target_ids, "rgbcmykw", iris.target_names): +for i, c, label in zip(target_ids, "rgbcmykw", iris.target_names, strict=False): plt.scatter(X_pca[y == i, 0], X_pca[y == i, 1], c=c, label=label) plt.legend() plt.show() diff --git a/packages/scikit-learn/examples/plot_tsne.py b/packages/scikit-learn/examples/plot_tsne.py index afd5805ca..ea35ed1a1 100644 --- a/packages/scikit-learn/examples/plot_tsne.py +++ b/packages/scikit-learn/examples/plot_tsne.py @@ -38,7 +38,7 @@ plt.figure(figsize=(6, 5)) colors = "r", "g", "b", "c", "m", "y", "k", "w", "orange", "purple" -for i, c, label in zip(target_ids, colors, digits.target_names): +for i, c, label in zip(target_ids, colors, digits.target_names, strict=True): plt.scatter(X_2d[y == i, 0], X_2d[y == i, 1], c=c, label=label) plt.legend() plt.show() diff --git a/ruff.toml b/ruff.toml index 24583d81f..a83da8581 100644 --- a/ruff.toml +++ b/ruff.toml @@ -2,18 +2,48 @@ target-version = "py310" [lint] select = [ - "UP", # pyupgrade - "C4", # flake8-comprehensions - "E713", # use 'key not in list' - "NPY201", # NumPy 2 compatibility - "PIE", # flake8-pie - "PGH003", # forbid blanket 'type: ignore' comments - "PLR0402", # useless import alias - "SIM101", # merge 'isinstance' calls - "SIM109", # use a tuple for multiple comparisons - "SIM110", # convert loop to 'any' - "SIM118", # use 'key in dict' - "SIM2", # simplify boolean comparisons + "B", # flake8-bugbear + "C4", # flake8-comprehensions + "E", # pycodestyle-error + "EM", # flake8-errmsg + "EXE", # flake8-executable + "FURB", # refurb + "NPY", # NumPy specific rules + "PD", # pandas-vet + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # pylint + # "PTH", # flake8-use-pathlib + "PYI", # flake8-pyi + # "RET", # flake8-return + "RUF", # ruff-specific + "SIM", # flake8-simplify + "SIM2", # simplify boolean comparisons + "UP", # pyupgrade + "YTT" # flake8-2020 +] +ignore = [ + "B006", # Do not use mutable data structures for argument defaults + "B007", # Loop control variable {name} not used within loop body + "B018", # Found useless expression. Either assign it to a variable or remove it. + "E402", # Module level import not at top of file + "E501", # Line too long + "E741", # Ambiguous variable name + "E721", # Do not compare types, use `isinstance()` + "E731", # Do not assign a `lambda` expression, use a `def` + "EM101", # Exception must not use a string literal, assign to variable first + "EM102", # Exception must not use an f-string literal, assign to variable first + "ISC001", # Conflicts with formatter + "NPY002", # Replace legacy np.random.{method_name} call with np.random.Generator + "PD002", # inplace=True should be avoided; it has inconsistent behavior + "PLR", # pylint-refactor + "PLR09", # Too many <...> + "PLR2004", # Magic value used in comparison + "PLW0127", # Self-assignment of variable {name} + "PLW2901", # Outer {outer_kind} variable {name} overwritten by inner {inner_kind} target + "RUF005", # Consider {expression} instead of concatenation + "RUF015", # Prefer next({iterable}) over single element slice + "SIM115" # Use context handler for opening files ] [format]