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 /benchmarks | |
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 'benchmarks')
-rw-r--r-- | benchmarks/command_packer_benchmark.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/benchmarks/command_packer_benchmark.py b/benchmarks/command_packer_benchmark.py index ae2e085..dae6fa4 100644 --- a/benchmarks/command_packer_benchmark.py +++ b/benchmarks/command_packer_benchmark.py @@ -13,8 +13,7 @@ class StringJoiningConnection(Connection): self.connect() try: self._sock.sendall(command) - except socket.error: - e = sys.exc_info()[1] + except socket.error as e: self.disconnect() if len(e.args) == 1: _errno, errmsg = 'UNKNOWN', e.args[0] @@ -22,9 +21,9 @@ class StringJoiningConnection(Connection): _errno, errmsg = e.args raise ConnectionError("Error %s while writing to socket. %s." % (_errno, errmsg)) - except Exception as e: + except Exception: self.disconnect() - raise e + raise def pack_command(self, *args): "Pack a series of arguments into a value Redis command" @@ -46,8 +45,7 @@ class ListJoiningConnection(Connection): command = [command] for item in command: self._sock.sendall(item) - except socket.error: - e = sys.exc_info()[1] + except socket.error as e: self.disconnect() if len(e.args) == 1: _errno, errmsg = 'UNKNOWN', e.args[0] @@ -55,9 +53,9 @@ class ListJoiningConnection(Connection): _errno, errmsg = e.args raise ConnectionError("Error %s while writing to socket. %s." % (_errno, errmsg)) - except Exception as e: + except Exception: self.disconnect() - raise e + raise def pack_command(self, *args): output = [] |