---
source: crates/ruff/src/rules/flake8_simplify/mod.rs
---
SIM105.py:4:1: SIM105 [*] Use `contextlib.suppress(ValueError)` instead of `try`-`except`-`pass`
   |
 4 |       pass
 5 |   
 6 | / try:
 7 | |     foo()
 8 | | except ValueError:  # SIM105
 9 | |     pass
   | |________^ SIM105
10 |   
11 |   try:
   |
   = help: Replace with `contextlib.suppress(ValueError)`

ℹ Suggested fix
  1 |+import contextlib
1 2 | def foo():
2 3 |     pass
3 4 | 
4   |-try:
  5 |+with contextlib.suppress(ValueError):
5 6 |     foo()
6   |-except ValueError:  # SIM105
7   |-    pass
8 7 | 
  8 |+
9 9 | try:
10 10 |     foo()
11 11 | except (ValueError, OSError):  # SIM105

SIM105.py:9:1: SIM105 [*] Use `contextlib.suppress(ValueError, OSError)` instead of `try`-`except`-`pass`
   |
 9 |       pass
10 |   
11 | / try:
12 | |     foo()
13 | | except (ValueError, OSError):  # SIM105
14 | |     pass
   | |________^ SIM105
15 |   
16 |   try:
   |
   = help: Replace with `contextlib.suppress(ValueError, OSError)`

ℹ Suggested fix
   1  |+import contextlib
1  2  | def foo():
2  3  |     pass
3  4  | 
--------------------------------------------------------------------------------
6  7  | except ValueError:  # SIM105
7  8  |     pass
8  9  | 
9     |-try:
   10 |+with contextlib.suppress(ValueError, OSError):
10 11 |     foo()
11    |-except (ValueError, OSError):  # SIM105
12    |-    pass
13 12 | 
   13 |+
14 14 | try:
15 15 |     foo()
16 16 | except:  # SIM105

SIM105.py:14:1: SIM105 [*] Use `contextlib.suppress(Exception)` instead of `try`-`except`-`pass`
   |
14 |       pass
15 |   
16 | / try:
17 | |     foo()
18 | | except:  # SIM105
19 | |     pass
   | |________^ SIM105
20 |   
21 |   try:
   |
   = help: Replace with `contextlib.suppress(Exception)`

ℹ Suggested fix
   1  |+import contextlib
1  2  | def foo():
2  3  |     pass
3  4  | 
--------------------------------------------------------------------------------
11 12 | except (ValueError, OSError):  # SIM105
12 13 |     pass
13 14 | 
14    |-try:
   15 |+with contextlib.suppress(Exception):
15 16 |     foo()
16    |-except:  # SIM105
17    |-    pass
18 17 | 
   18 |+
19 19 | try:
20 20 |     foo()
21 21 | except (a.Error, b.Error):  # SIM105

SIM105.py:19:1: SIM105 [*] Use `contextlib.suppress(a.Error, b.Error)` instead of `try`-`except`-`pass`
   |
19 |       pass
20 |   
21 | / try:
22 | |     foo()
23 | | except (a.Error, b.Error):  # SIM105
24 | |     pass
   | |________^ SIM105
25 |   
26 |   try:
   |
   = help: Replace with `contextlib.suppress(a.Error, b.Error)`

ℹ Suggested fix
   1  |+import contextlib
1  2  | def foo():
2  3  |     pass
3  4  | 
--------------------------------------------------------------------------------
16 17 | except:  # SIM105
17 18 |     pass
18 19 | 
19    |-try:
   20 |+with contextlib.suppress(a.Error, b.Error):
20 21 |     foo()
21    |-except (a.Error, b.Error):  # SIM105
22    |-    pass
23 22 | 
   23 |+
24 24 | try:
25 25 |     foo()
26 26 | except ValueError:

SIM105.py:64:5: SIM105 [*] Use `contextlib.suppress(ValueError)` instead of `try`-`except`-`pass`
   |
64 |   def with_ellipsis():
65 |       try:
   |  _____^
66 | |         foo()
67 | |     except ValueError:
68 | |         ...
   | |___________^ SIM105
69 |   
70 |   def with_ellipsis_and_return():
   |
   = help: Replace with `contextlib.suppress(ValueError)`

ℹ Suggested fix
   1  |+import contextlib
1  2  | def foo():
2  3  |     pass
3  4  | 
--------------------------------------------------------------------------------
61 62 |         pass
62 63 | 
63 64 | def with_ellipsis():
64    |-    try:
   65 |+    with contextlib.suppress(ValueError):
65 66 |         foo()
66    |-    except ValueError:
67    |-        ...
68 67 | 
   68 |+
69 69 | def with_ellipsis_and_return():
70 70 |     try:
71 71 |         return foo()


