Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ impl Violation for SuppressibleException {

fn fix_title(&self) -> Option<String> {
let SuppressibleException { exception } = self;
Some(format!("Replace with `contextlib.suppress({exception})`"))
Some(format!(
"Replace `try`-`except`-`pass` with `with contextlib.suppress({exception}): ...`"
))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...`
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading