diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs index 34c4915f3b..d3b93e3dbb 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs @@ -58,7 +58,9 @@ impl Violation for SuppressibleException { fn fix_title(&self) -> Option { let SuppressibleException { exception } = self; - Some(format!("Replace with `contextlib.suppress({exception})`")) + Some(format!( + "Replace `try`-`except`-`pass` with `with contextlib.suppress({exception}): ...`" + )) } } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_0.py.snap b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_0.py.snap index 0a05a9ca89..26a37405fa 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_0.py.snap +++ b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_0.py.snap @@ -11,7 +11,7 @@ SIM105 [*] Use `contextlib.suppress(ValueError)` instead of `try`-`except`-`pass 9 | | pass | |________^ | -help: Replace with `contextlib.suppress(ValueError)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(ValueError): ...` 1 + import contextlib 2 | def foo(): 3 | pass @@ -40,7 +40,7 @@ SIM105 [*] Use `contextlib.suppress(ValueError, OSError)` instead of `try`-`exce 17 | 18 | # SIM105 | -help: Replace with `contextlib.suppress(ValueError, OSError)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(ValueError, OSError): ...` 1 + import contextlib 2 | def foo(): 3 | pass @@ -71,7 +71,7 @@ SIM105 [*] Use `contextlib.suppress(ValueError, OSError)` instead of `try`-`exce 23 | 24 | # SIM105 | -help: Replace with `contextlib.suppress(ValueError, OSError)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(ValueError, OSError): ...` 1 + import contextlib 2 | def foo(): 3 | pass @@ -102,7 +102,7 @@ SIM105 [*] Use `contextlib.suppress(BaseException)` instead of `try`-`except`-`p 29 | 30 | # SIM105 | -help: Replace with `contextlib.suppress(BaseException)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(BaseException): ...` 1 + import contextlib 2 + import builtins 3 | def foo(): @@ -134,7 +134,7 @@ SIM105 [*] Use `contextlib.suppress(a.Error, b.Error)` instead of `try`-`except` 35 | 36 | # OK | -help: Replace with `contextlib.suppress(a.Error, b.Error)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(a.Error, b.Error): ...` 1 + import contextlib 2 | def foo(): 3 | pass @@ -164,7 +164,7 @@ SIM105 [*] Use `contextlib.suppress(ValueError)` instead of `try`-`except`-`pass 88 | | ... | |___________^ | -help: Replace with `contextlib.suppress(ValueError)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(ValueError): ...` 1 + import contextlib 2 | def foo(): 3 | pass @@ -195,7 +195,7 @@ SIM105 Use `contextlib.suppress(ValueError, OSError)` instead of `try`-`except`- 104 | 105 | try: | -help: Replace with `contextlib.suppress(ValueError, OSError)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(ValueError, OSError): ...` SIM105 [*] Use `contextlib.suppress(OSError)` instead of `try`-`except`-`pass` --> SIM105_0.py:117:5 @@ -210,7 +210,7 @@ SIM105 [*] Use `contextlib.suppress(OSError)` instead of `try`-`except`-`pass` 121 | 122 | try: os.makedirs(model_dir); | -help: Replace with `contextlib.suppress(OSError)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(OSError): ...` 1 + import contextlib 2 | def foo(): 3 | pass @@ -241,7 +241,7 @@ SIM105 [*] Use `contextlib.suppress(OSError)` instead of `try`-`except`-`pass` 125 | 126 | try: os.makedirs(model_dir); | -help: Replace with `contextlib.suppress(OSError)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(OSError): ...` 1 + import contextlib 2 | def foo(): 3 | pass @@ -271,7 +271,7 @@ SIM105 [*] Use `contextlib.suppress(OSError)` instead of `try`-`except`-`pass` 129 | \ 130 | # | -help: Replace with `contextlib.suppress(OSError)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(OSError): ...` 1 + import contextlib 2 | def foo(): 3 | pass @@ -299,7 +299,7 @@ SIM105 [*] Use `contextlib.suppress()` instead of `try`-`except`-`pass` 136 | | pass | |________^ | -help: Replace with `contextlib.suppress()` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(): ...` 1 + import contextlib 2 | def foo(): 3 | pass @@ -328,7 +328,7 @@ SIM105 [*] Use `contextlib.suppress(BaseException)` instead of `try`-`except`-`p 143 | | pass | |________^ | -help: Replace with `contextlib.suppress(BaseException)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(BaseException): ...` 1 + import contextlib 2 | def foo(): 3 | pass diff --git a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_1.py.snap b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_1.py.snap index 79aab24239..9ad5a3c17e 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_1.py.snap +++ b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_1.py.snap @@ -11,7 +11,7 @@ SIM105 [*] Use `contextlib.suppress(ValueError)` instead of `try`-`except`-`pass 8 | | pass | |________^ | -help: Replace with `contextlib.suppress(ValueError)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(ValueError): ...` 1 | """Case: There's a random import, so it should add `contextlib` after it.""" 2 | import math 3 + import contextlib diff --git a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_2.py.snap b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_2.py.snap index 88621f5d35..2f73d90197 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_2.py.snap +++ b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_2.py.snap @@ -11,7 +11,7 @@ SIM105 [*] Use `contextlib.suppress(ValueError)` instead of `try`-`except`-`pass 13 | | pass | |________^ | -help: Replace with `contextlib.suppress(ValueError)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(ValueError): ...` 7 | 8 | 9 | # SIM105 diff --git a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_3.py.snap b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_3.py.snap index 385aabd5de..3f4f3a5e14 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_3.py.snap +++ b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_3.py.snap @@ -12,4 +12,4 @@ SIM105 Use `contextlib.suppress(ValueError)` instead of `try`-`except`-`pass` 13 | | pass | |____________^ | -help: Replace with `contextlib.suppress(ValueError)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(ValueError): ...` diff --git a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_4.py.snap b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_4.py.snap index 78413d7d1f..da7e0842f7 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_4.py.snap +++ b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM105_SIM105_4.py.snap @@ -10,7 +10,7 @@ SIM105 [*] Use `contextlib.suppress(ImportError)` instead of `try`-`except`-`pas 4 | | except ImportError: pass | |___________________________^ | -help: Replace with `contextlib.suppress(ImportError)` +help: Replace `try`-`except`-`pass` with `with contextlib.suppress(ImportError): ...` 1 | #!/usr/bin/env python - try: 2 + import contextlib