Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify exception handlers #1319

Merged
merged 1 commit into from
Apr 11, 2020
Merged

Simplify exception handlers #1319

merged 1 commit into from
Apr 11, 2020

Conversation

jdufresne
Copy link
Contributor

Use the "as" keyword to capture the exception in a variable instead of
sys.exc_info().

Re-raise exception with the bare "raise" syntax.

Avoid "# noqa: E722" by catching BaseException, which includes all
exceptions including SystemExit.

Pull Request check-list

Please make sure to review and check all of these items:

  • Does $ tox pass with this change (including linting)?
  • Does travis tests pass with this change (enable it first in your forked repo and wait for the travis build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.

Use the "as" keyword to capture the exception in a variable instead of
sys.exc_info().

Re-raise exception with the bare "raise" syntax.

Avoid "# noqa: E722" by catching BaseException, which includes all
exceptions including SystemExit.
@codecov-io
Copy link

codecov-io commented Apr 10, 2020

Codecov Report

Merging #1319 into master will increase coverage by 0.02%.
The diff coverage is 60.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1319      +/-   ##
==========================================
+ Coverage   92.82%   92.84%   +0.02%     
==========================================
  Files          19       19              
  Lines        6533     6529       -4     
==========================================
- Hits         6064     6062       -2     
+ Misses        469      467       -2     
Impacted Files Coverage Δ
redis/connection.py 82.21% <57.14%> (+0.19%) ⬆️
redis/client.py 86.27% <62.50%> (-0.01%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 98242bb...f7a27a5. Read the comment docs.

@andymccurdy
Copy link
Contributor

@jdufresne If I recall correctly, the except clauses that were empty (with the #noqa E722) for a specific reason. #328, #360 and #1128 have more details.

@jdufresne
Copy link
Contributor Author

Yeah, that makes sense.

The old version you linked to used except Exception which does not catch SystemExit or KeyboardInterrupt. But BaseException is the base class of all exceptions and so is equivalent to a bare except: but it also signals to the reader (and tools) that all exceptions are intentionally caught and it is not simply an oversight due to an omission.

So, IMO, I this version is still preferable as it follows community conventions for catching all exceptions and avoids the need to squelch the tool. WDYT?

@andymccurdy
Copy link
Contributor

Oh, gotcha. BaseException makes sense then.

@andymccurdy andymccurdy merged commit ae86503 into redis:master Apr 11, 2020
@jdufresne jdufresne deleted the exc branch April 11, 2020 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants