Skip to content

Commit

Permalink
Update docs for FURB107 (use-suppress) (#292):
Browse files Browse the repository at this point in the history
  • Loading branch information
dosisod authored Oct 3, 2023
1 parent 706b451 commit 14cfc38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions docs/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ spaces_4 = "\thello world".expandtabs(4)

Categories: `contextlib` `readability`

Often times you want to handle an exception, and just ignore it. You can do
this with a `try/except` block, using a single `pass` in the `except`
Often times you want to handle an exception and just ignore it. You can do
this with a `try`/`except` block with a single `pass` in the `except`
block, but there is a simpler and more concise way using the `suppress()`
function from `contextlib`:

Expand All @@ -164,6 +164,9 @@ with suppress(FileNotFoundError):
f()
```

Note: `suppress()` is slower than using `try`/`except`, so for performance
critical code you might consider ignoring this check.

## FURB108: `use-in-oper`

Categories: `logical` `readability`
Expand Down
7 changes: 5 additions & 2 deletions refurb/checks/contextlib/with_suppress.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
@dataclass
class ErrorInfo(Error):
"""
Often times you want to handle an exception, and just ignore it. You can do
this with a `try/except` block, using a single `pass` in the `except`
Often times you want to handle an exception and just ignore it. You can do
this with a `try`/`except` block with a single `pass` in the `except`
block, but there is a simpler and more concise way using the `suppress()`
function from `contextlib`:
Expand All @@ -29,6 +29,9 @@ class ErrorInfo(Error):
with suppress(FileNotFoundError):
f()
```
Note: `suppress()` is slower than using `try`/`except`, so for performance
critical code you might consider ignoring this check.
"""

name = "use-with-suppress"
Expand Down

0 comments on commit 14cfc38

Please sign in to comment.