diff options
author | Hugo Osvaldo Barrera <hugo@whynothugo.nl> | 2023-06-06 12:02:26 +0200 |
---|---|---|
committer | Hugo Osvaldo Barrera <hugo@whynothugo.nl> | 2023-06-06 12:22:51 +0200 |
commit | c12e12626d040fa81489e9196daed6cc189d4239 (patch) | |
tree | 35b940c3da5ebfa214260b5cba689b1430425377 | |
parent | 0cec8c0e802c63331481dff6f58ddd07fb5ebb7e (diff) |
Use contextlib.suppress to suppress exceptions
-rw-r--r-- | khal/ui/__init__.py | 23 | ||||
-rw-r--r-- | khal/ui/base.py | 6 |
2 files changed, 14 insertions, 15 deletions
diff --git a/khal/ui/__init__.py b/khal/ui/__init__.py index 0f7bbe44..cbf076a0 100644 --- a/khal/ui/__init__.py +++ b/khal/ui/__init__.py @@ -19,6 +19,7 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +import contextlib import datetime as dt import logging import signal @@ -292,10 +293,9 @@ class DListBox(EventListBox): def ensure_date(self, day): """ensure an entry for `day` exists and bring it into focus""" - try: + with contextlib.suppress(IndexError): self._old_focus = self.focus_position - except IndexError: - pass + rval = self.body.ensure_date(day) self.clean() return rval @@ -312,10 +312,9 @@ class DListBox(EventListBox): rval = super().keypress(size, key) self.clean() if key in ['up', 'down']: - try: + with contextlib.suppress(IndexError): self._old_focus = self.focus_position - except IndexError: - pass + day = self.body[self.body.focus].date # we need to save DateListBox.selected_date and reset it later, because @@ -855,10 +854,9 @@ class EventColumn(urwid.WidgetWrap): if isinstance(end_date, dt.datetime): end_date = end_date.date() self.pane.eventscolumn.base_widget.update(start_date, end_date, event.recurring) - try: + with contextlib.suppress(IndexError): self._old_focus = self.focus_position - except IndexError: - pass + def new(self, date: dt.date, end: Optional[dt.date]=None): """create a new event on `date` at the next full hour and edit it @@ -1354,9 +1352,10 @@ def start_pane(pane, callback, program_info='', quit_keys=None): except Exception: import traceback tb = traceback.format_exc() - try: # Try to leave terminal in usable state + + # Try to leave terminal in usable state + with contextlib.suppress(Exception): loop.stop() - except Exception: - pass + print(tb) sys.exit(1) diff --git a/khal/ui/base.py b/khal/ui/base.py index 067935bc..eac5b42b 100644 --- a/khal/ui/base.py +++ b/khal/ui/base.py @@ -23,6 +23,7 @@ """this module should contain classes that are specific to ikhal, more general widgets should go in widgets.py""" +import contextlib import logging import threading import time @@ -266,8 +267,7 @@ class AlertDaemon(threading.Thread): while True: _event.wait() _sleep(3) - try: + with contextlib.suppress(_exception): _set_msg(None) - except _exception: - pass + _event.clear() |