Skip to content

Commit 1461a16

Browse files
dependabot[bot]justinchubygithub-advanced-security[bot]
authored
Bump ruff from 0.5.4 to 0.9.1 (microsoft#23328)
Bumps [ruff](https://github.com/astral-sh/ruff) from 0.5.4 to 0.9.1. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/astral-sh/ruff/releases">ruff's releases</a>.</em></p> <blockquote> <h2>0.9.1</h2> <h2>Release Notes</h2> <h3>Preview features</h3> <ul> <li>[<code>pycodestyle</code>] Run <code>too-many-newlines-at-end-of-file</code> on each cell in notebooks (<code>W391</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/15308">#15308</a>)</li> <li>[<code>ruff</code>] Omit diagnostic for shadowed private function parameters in <code>used-dummy-variable</code> (<code>RUF052</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/15376">#15376</a>)</li> </ul> <h3>Rule changes</h3> <ul> <li>[<code>flake8-bugbear</code>] Improve <code>assert-raises-exception</code> message (<code>B017</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/15389">#15389</a>)</li> </ul> <h3>Formatter</h3> <ul> <li>Preserve trailing end-of line comments for the last string literal in implicitly concatenated strings (<a href="https://redirect.github.com/astral-sh/ruff/pull/15378">#15378</a>)</li> </ul> <h3>Server</h3> <ul> <li>Fix a bug where the server and client notebooks were out of sync after reordering cells (<a href="https://redirect.github.com/astral-sh/ruff/pull/15398">#15398</a>)</li> </ul> <h3>Bug fixes</h3> <ul> <li>[<code>flake8-pie</code>] Correctly remove wrapping parentheses (<code>PIE800</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/15394">#15394</a>)</li> <li>[<code>pyupgrade</code>] Handle comments and multiline expressions correctly (<code>UP037</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/15337">#15337</a>)</li> </ul> <h2>Contributors</h2> <ul> <li><a href="https://github.com/AntoineD"><code>@​AntoineD</code></a></li> <li><a href="https://github.com/InSyncWithFoo"><code>@​InSyncWithFoo</code></a></li> <li><a href="https://github.com/MichaReiser"><code>@​MichaReiser</code></a></li> <li><a href="https://github.com/calumy"><code>@​calumy</code></a></li> <li><a href="https://github.com/dcreager"><code>@​dcreager</code></a></li> <li><a href="https://github.com/dhruvmanila"><code>@​dhruvmanila</code></a></li> <li><a href="https://github.com/dylwil3"><code>@​dylwil3</code></a></li> <li><a href="https://github.com/sharkdp"><code>@​sharkdp</code></a></li> <li><a href="https://github.com/tjkuson"><code>@​tjkuson</code></a></li> </ul> <h2>Install ruff 0.9.1</h2> <h3>Install prebuilt binaries via shell script</h3> <pre lang="sh"><code>curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/ruff/releases/download/0.9.1/ruff-installer.sh | sh </code></pre> <h3>Install prebuilt binaries via powershell script</h3> <pre lang="sh"><code>powershell -ExecutionPolicy ByPass -c &quot;irm https://github.com/astral-sh/ruff/releases/download/0.9.1/ruff-installer.ps1 | iex&quot; </code></pre> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md">ruff's changelog</a>.</em></p> <blockquote> <h2>0.9.1</h2> <h3>Preview features</h3> <ul> <li>[<code>pycodestyle</code>] Run <code>too-many-newlines-at-end-of-file</code> on each cell in notebooks (<code>W391</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/15308">#15308</a>)</li> <li>[<code>ruff</code>] Omit diagnostic for shadowed private function parameters in <code>used-dummy-variable</code> (<code>RUF052</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/15376">#15376</a>)</li> </ul> <h3>Rule changes</h3> <ul> <li>[<code>flake8-bugbear</code>] Improve <code>assert-raises-exception</code> message (<code>B017</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/15389">#15389</a>)</li> </ul> <h3>Formatter</h3> <ul> <li>Preserve trailing end-of line comments for the last string literal in implicitly concatenated strings (<a href="https://redirect.github.com/astral-sh/ruff/pull/15378">#15378</a>)</li> </ul> <h3>Server</h3> <ul> <li>Fix a bug where the server and client notebooks were out of sync after reordering cells (<a href="https://redirect.github.com/astral-sh/ruff/pull/15398">#15398</a>)</li> </ul> <h3>Bug fixes</h3> <ul> <li>[<code>flake8-pie</code>] Correctly remove wrapping parentheses (<code>PIE800</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/15394">#15394</a>)</li> <li>[<code>pyupgrade</code>] Handle comments and multiline expressions correctly (<code>UP037</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/15337">#15337</a>)</li> </ul> <h2>0.9.0</h2> <p>Check out the <a href="https://astral.sh/blog/ruff-v0.9.0">blog post</a> for a migration guide and overview of the changes!</p> <h3>Breaking changes</h3> <p>Ruff now formats your code according to the 2025 style guide. As a result, your code might now get formatted differently. See the formatter section for a detailed list of changes.</p> <p>This release doesn’t remove or remap any existing stable rules.</p> <h3>Stabilization</h3> <p>The following rules have been stabilized and are no longer in preview:</p> <ul> <li><a href="https://docs.astral.sh/ruff/rules/stdlib-module-shadowing/"><code>stdlib-module-shadowing</code></a> (<code>A005</code>). This rule has also been renamed: previously, it was called <code>builtin-module-shadowing</code>.</li> <li><a href="https://docs.astral.sh/ruff/rules/builtin-lambda-argument-shadowing/"><code>builtin-lambda-argument-shadowing</code></a> (<code>A006</code>)</li> <li><a href="https://docs.astral.sh/ruff/rules/slice-to-remove-prefix-or-suffix/"><code>slice-to-remove-prefix-or-suffix</code></a> (<code>FURB188</code>)</li> <li><a href="https://docs.astral.sh/ruff/rules/boolean-chained-comparison/"><code>boolean-chained-comparison</code></a> (<code>PLR1716</code>)</li> <li><a href="https://docs.astral.sh/ruff/rules/decimal-from-float-literal/"><code>decimal-from-float-literal</code></a> (<code>RUF032</code>)</li> <li><a href="https://docs.astral.sh/ruff/rules/post-init-default/"><code>post-init-default</code></a> (<code>RUF033</code>)</li> <li><a href="https://docs.astral.sh/ruff/rules/useless-if-else/"><code>useless-if-else</code></a> (<code>RUF034</code>)</li> </ul> <p>The following behaviors have been stabilized:</p> <ul> <li><a href="https://docs.astral.sh/ruff/rules/pytest-parametrize-names-wrong-type/"><code>pytest-parametrize-names-wrong-type</code></a> (<code>PT006</code>): Detect <a href="https://docs.pytest.org/en/7.1.x/how-to/parametrize.html#parametrize"><code>pytest.parametrize</code></a> calls outside decorators and calls with keyword arguments.</li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/astral-sh/ruff/commit/12f86f39a4691e44b62c11dd4bc376a16e358f43"><code>12f86f3</code></a> Ruff 0.9.1 (<a href="https://redirect.github.com/astral-sh/ruff/issues/15407">#15407</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/2b28d566a4a891339a43a35c818f5b155c0b9edd"><code>2b28d56</code></a> Associate a trailing end-of-line comment in a parenthesized implicit concaten...</li> <li><a href="https://github.com/astral-sh/ruff/commit/adca7bd95cf315ca14e34ab3eac6deb73e154f1d"><code>adca7bd</code></a> Remove pygments pin (<a href="https://redirect.github.com/astral-sh/ruff/issues/15404">#15404</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/6b98a26452ec1bde8b445c82c097d03c78213c1d"><code>6b98a26</code></a> [red-knot] Support <code>assert_type</code> (<a href="https://redirect.github.com/astral-sh/ruff/issues/15194">#15194</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/c87463842a6e19976b6f3401137b6932e4a7bb71"><code>c874638</code></a> [red-knot] Move tuple-containing-Never tests to Markdown (<a href="https://redirect.github.com/astral-sh/ruff/issues/15402">#15402</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/c364b586f9177a22f4556f86e434f21dfaf82c38"><code>c364b58</code></a> [<code>flake8-pie</code>] Correctly remove wrapping parentheses (<code>PIE800</code>) (<a href="https://redirect.github.com/astral-sh/ruff/issues/15394">#15394</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/73d424ee5e6963d577e196d71c3b19c82e84e612"><code>73d424e</code></a> Fix outdated doc for handling the default file types with the pre-commit hook...</li> <li><a href="https://github.com/astral-sh/ruff/commit/6e9ff445fd8559972b423370de20563a9c2db8d4"><code>6e9ff44</code></a> Insert the cells from the <code>start</code> position (<a href="https://redirect.github.com/astral-sh/ruff/issues/15398">#15398</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/f2c3ddc5eaa2ce107a200e134be82fc36afce06b"><code>f2c3ddc</code></a> [red-knot] Move intersection type tests to Markdown (<a href="https://redirect.github.com/astral-sh/ruff/issues/15396">#15396</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/b861551b6ac928c25136d76151162f6fefc9cf71"><code>b861551</code></a> Remove unnecessary backticks (<a href="https://redirect.github.com/astral-sh/ruff/issues/15393">#15393</a>)</li> <li>Additional commits viewable in <a href="https://github.com/astral-sh/ruff/compare/0.5.4...0.9.1">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=ruff&package-manager=pip&previous-version=0.5.4&new-version=0.9.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 6a7ea5c commit 1461a16

35 files changed

+74
-79
lines changed

docs/python/examples/plot_train_convert_predict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ def sess_predict_proba_rf(x):
212212
rf.fit(X_train, y_train)
213213
initial_type = [("float_input", FloatTensorType([1, 4]))]
214214
onx = convert_sklearn(rf, initial_types=initial_type)
215-
with open("rf_iris_%d.onnx" % n_trees, "wb") as f:
215+
with open(f"rf_iris_{n_trees}.onnx", "wb") as f:
216216
f.write(onx.SerializeToString())
217-
sess = rt.InferenceSession("rf_iris_%d.onnx" % n_trees, providers=rt.get_available_providers())
217+
sess = rt.InferenceSession(f"rf_iris_{n_trees}.onnx", providers=rt.get_available_providers())
218218

219219
def sess_predict_proba_loop(x):
220220
return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0] # noqa: B023

onnxruntime/python/tools/quantization/calibrate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class CalibrationMethod(Enum):
161161
class CalibrationDataReader(metaclass=abc.ABCMeta):
162162
@classmethod
163163
def __subclasshook__(cls, subclass):
164-
return hasattr(subclass, "get_next") and callable(subclass.get_next) or NotImplemented
164+
return (hasattr(subclass, "get_next") and callable(subclass.get_next)) or NotImplemented
165165

166166
@abc.abstractmethod
167167
def get_next(self) -> dict:

onnxruntime/python/tools/quantization/quant_utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -907,11 +907,7 @@ def smooth_distribution(p, eps=0.0001):
907907
# raise ValueError('The discrete probability distribution is malformed. All entries are 0.')
908908
return None
909909
eps1 = eps * float(n_zeros) / float(n_nonzeros)
910-
assert eps1 < 1.0, "n_zeros=%d, n_nonzeros=%d, eps1=%f" % (
911-
n_zeros,
912-
n_nonzeros,
913-
eps1,
914-
)
910+
assert eps1 < 1.0, f"n_zeros={n_zeros}, n_nonzeros={n_nonzeros}, eps1={eps1}"
915911

916912
hist = p.astype(numpy.float32)
917913
hist += eps * is_zeros + (-eps1) * is_nonzeros

onnxruntime/python/tools/tensorrt/perf/build/ort_build_latest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ def main():
4444
cmake_tar = "cmake-3.28.3-linux-x86_64.tar.gz"
4545
if not os.path.exists(cmake_tar):
4646
subprocess.run(["wget", "-c", "https://cmake.org/files/v3.28/" + cmake_tar], check=True)
47-
tar = tarfile.open(cmake_tar)
48-
tar.extractall()
49-
tar.close()
47+
with tarfile.open(cmake_tar) as tar:
48+
tar.extractall()
5049

5150
os.environ["PATH"] = os.path.join(os.path.abspath("cmake-3.28.3-linux-x86_64"), "bin") + ":" + os.environ["PATH"]
5251
os.environ["CUDACXX"] = os.path.join(args.cuda_home, "bin", "nvcc")

onnxruntime/python/tools/tensorrt/perf/setup_scripts/setup_onnx_zoo.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ def create_model_folder(model):
1717
def extract_and_get_files(file_name):
1818
model_folder = file_name.replace(".tar.gz", "") + "/"
1919
create_model_folder(model_folder)
20-
model_tar = tarfile.open(file_name)
21-
model_tar.extractall(model_folder)
22-
file_list = model_tar.getnames()
23-
file_list.sort()
24-
model_tar.close()
20+
with tarfile.open(file_name) as model_tar:
21+
for member in model_tar.getmembers():
22+
if os.path.isabs(member.name) or ".." in member.name:
23+
raise ValueError(f"Illegal tar archive entry: {member.name}")
24+
model_tar.extractall(model_folder)
25+
file_list = model_tar.getnames()
26+
file_list.sort()
2527
return model_folder, file_list
2628

2729

onnxruntime/test/python/onnxruntime_test_python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def cuda_device_count(self, cuda_lib):
8585
if result != 0:
8686
error_str = ctypes.c_char_p()
8787
cuda_lib.cuGetErrorString(result, ctypes.byref(error_str))
88-
print("cuDeviceGetCount failed with error code %d: %s" % (result, error_str.value.decode()))
88+
print(f"cuDeviceGetCount failed with error code {result}: {error_str.value.decode()}")
8989
return -1
9090
return num_device.value
9191

onnxruntime/test/python/onnxruntime_test_python_iobinding.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def test_bind_onnx_types_not_supported_by_numpy(self):
221221
)
222222

223223
for inner_device, provider in devices:
224-
for onnx_dtype in onnx_to_torch_type_map:
224+
for onnx_dtype, torch_dtype in onnx_to_torch_type_map.items():
225225
with self.subTest(onnx_dtype=onnx_dtype, inner_device=str(inner_device)):
226226

227227
# Create onnx graph with dynamic axes
@@ -239,7 +239,6 @@ def test_bind_onnx_types_not_supported_by_numpy(self):
239239

240240
sess = onnxrt.InferenceSession(model_def.SerializeToString(), providers=provider)
241241

242-
torch_dtype = onnx_to_torch_type_map[onnx_dtype]
243242
x = torch.arange(8).to(torch_dtype)
244243
y = torch.empty(8, dtype=torch_dtype)
245244

onnxruntime/test/python/onnxruntime_test_scatternd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def common_scatter(self, opset, providers, dtype, reduction, expected_names):
8888
self.assertEqual(expected_names, names)
8989

9090
sonx = str(onx).replace(" ", "").replace("\n", "|")
91-
sexp = 'op_type:"Cast"|attribute{|name:"to"|type:INT|i:%d|}' % itype
92-
sexp2 = 'op_type:"Cast"|attribute{|name:"to"|i:%d|type:INT|}' % itype
91+
sexp = 'op_type:"Cast"|attribute{|name:"to"|type:INT|i:%d|}' % itype # noqa: UP031
92+
sexp2 = 'op_type:"Cast"|attribute{|name:"to"|i:%d|type:INT|}' % itype # noqa: UP031
9393
assert sexp in sonx or sexp2 in sonx, f"Unable to find a substring in {sonx!r}"
9494
if providers == ["CPUExecutionProvider"]:
9595
return

onnxruntime/test/python/quantization/op_test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,10 @@ def check_op_type_count(testcase, model_path, **kwargs):
379379
if node.op_type in optype2count:
380380
optype2count[node.op_type] += 1
381381

382-
for op_type in kwargs:
382+
for op_type, value in kwargs.items():
383383
try:
384384
testcase.assertEqual(
385-
kwargs[op_type],
385+
value,
386386
optype2count[op_type],
387387
f"op_type {op_type} count not same",
388388
)

onnxruntime/test/python/quantization/test_calibration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ def test_compute_data(self):
361361
min_max_pairs = list(zip(rmin, rmax))
362362
output_names = [infer_session.get_outputs()[i].name for i in range(len(infer_session.get_outputs()))]
363363
output_min_max_dict = dict(zip(output_names, min_max_pairs))
364-
for output_name in output_min_max_dict:
365-
self.assertEqual(output_min_max_dict[output_name], tensors_range[output_name].range_value)
364+
for output_name, min_max in output_min_max_dict.items():
365+
self.assertEqual(min_max, tensors_range[output_name].range_value)
366366

367367
def test_histogram_calibrators_run(self):
368368
"""
@@ -524,8 +524,8 @@ def test_compute_data_per_channel(self):
524524
min_max_pairs = list(zip(rmin, rmax))
525525
output_names = [infer_session.get_outputs()[i].name for i in range(len(infer_session.get_outputs()))]
526526
output_min_max_dict = dict(zip(output_names, min_max_pairs))
527-
for output_name in output_min_max_dict:
528-
np.testing.assert_equal(output_min_max_dict[output_name], tensors_range[output_name].range_value)
527+
for output_name, min_max in output_min_max_dict.items():
528+
np.testing.assert_equal(min_max, tensors_range[output_name].range_value)
529529

530530

531531
if __name__ == "__main__":

0 commit comments

Comments
 (0)