diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2020-04-11 12:47:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-11 12:47:38 -0700 |
commit | ae86503e4c9348e43dd927b4a552d72349faf097 (patch) | |
tree | bc06f3f1c6bda67c3f8dc2553a9f6bdbbff81e50 /redis/client.py | |
parent | 2fcd5471105ccb93cc3b06fc83abfd86174dde89 (diff) | |
download | redis-py-ae86503e4c9348e43dd927b4a552d72349faf097.tar.gz |
Simplify exception handlers (#1319)
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.
Diffstat (limited to 'redis/client.py')
-rwxr-xr-x | redis/client.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/redis/client.py b/redis/client.py index 07aa9f6..7454321 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3887,8 +3887,8 @@ class Pipeline(Redis): # the socket try: self.parse_response(connection, '_') - except ResponseError: - errors.append((0, sys.exc_info()[1])) + except ResponseError as e: + errors.append((0, e)) # and all the other commands for i, command in enumerate(commands): @@ -3897,10 +3897,9 @@ class Pipeline(Redis): else: try: self.parse_response(connection, '_') - except ResponseError: - ex = sys.exc_info()[1] - self.annotate_exception(ex, i + 1, command[0]) - errors.append((i, ex)) + except ResponseError as e: + self.annotate_exception(e, i + 1, command[0]) + errors.append((i, e)) # parse the EXEC. try: @@ -3908,7 +3907,7 @@ class Pipeline(Redis): except ExecAbortError: if errors: raise errors[0][1] - raise sys.exc_info()[1] + raise # EXEC clears any watched keys self.watching = False @@ -3950,8 +3949,8 @@ class Pipeline(Redis): try: response.append( self.parse_response(connection, args[0], **options)) - except ResponseError: - response.append(sys.exc_info()[1]) + except ResponseError as e: + response.append(e) if raise_on_error: self.raise_first_error(commands, response) |