diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cc46ffea2..9f21dc718 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: - id: check-added-large-files - id: debug-statements - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.17.1 + rev: v2.4.0 hooks: - id: mypy additional_dependencies: @@ -19,7 +19,7 @@ repos: - types-setuptools - types-python-dateutil - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.15.7' + rev: 'v0.17.0' hooks: - id: ruff args: ["--fix"] diff --git a/khal/controllers.py b/khal/controllers.py index 6148f29ec..a870e0f06 100644 --- a/khal/controllers.py +++ b/khal/controllers.py @@ -220,9 +220,12 @@ def get_events_between( # yes the logic could be simplified, but I believe it's easier # to understand what's going on here this way if notstarted: - if event.allday and event.start < original_start.date(): - continue - elif not event.allday and event.start_local < original_start: + if ( + event.allday + and event.start < original_start.date() + or not event.allday + and event.start_local < original_start + ): continue if seen is not None and event.uid in seen: continue @@ -659,9 +662,12 @@ def edit(collection, search_string, locale, format=None, allow_past=False, conf= events = sorted(collection.search(search_string)) for event in events: if not allow_past: - if event.allday and event.end < now.date(): - continue - elif not event.allday and event.end_local < now: + if ( + event.allday + and event.end < now.date() + or not event.allday + and event.end_local < now + ): continue event_text = textwrap.wrap( human_formatter(format)(event.attributes(relative_to=now)), term_width diff --git a/khal/khalendar/backend.py b/khal/khalendar/backend.py index 025ae2586..8ee5eade4 100644 --- a/khal/khalendar/backend.py +++ b/khal/khalendar/backend.py @@ -108,7 +108,7 @@ def at_once(self) -> Iterator["SQLiteDb"]: def _create_dbdir(self) -> None: """create the dbdir if it doesn't exist""" if self.db_path == ":memory:": - return None + return dbdir = self.db_path.rsplit("/", 1)[0] if not path.isdir(dbdir): try: diff --git a/khal/ui/__init__.py b/khal/ui/__init__.py index 39594dcd1..21ff0ee3a 100644 --- a/khal/ui/__init__.py +++ b/khal/ui/__init__.py @@ -410,9 +410,7 @@ def ensure_date(self, day: dt.date) -> None: def days_to_next_already_loaded(self, day: dt.date) -> int: """return number of days until `day` is already loaded into the CalendarWidget""" - if len(self) == 0: - return 0 - elif self[0].date <= day <= self[-1].date: + if len(self) == 0 or self[0].date <= day <= self[-1].date: return 0 elif day <= self[0].date: return (self[0].date - day).days @@ -891,7 +889,7 @@ def duplicate(self) -> None: # which are also copied. If the events' summary is edited it will show # up on disk but not be displayed in khal if self.focus_event is None: - return None + return event = self.focus_event.event.duplicate() try: self.pane.collection.insert(event) diff --git a/khal/ui/base.py b/khal/ui/base.py index 602ec0a25..70ff23a08 100644 --- a/khal/ui/base.py +++ b/khal/ui/base.py @@ -216,9 +216,7 @@ def is_top_level(self): def on_key_press(self, key): """Handle application-wide key strokes.""" - if key in self.quit_keys: - self.backtrack() - elif key == "esc" and not self.is_top_level(): + if key in self.quit_keys or key == "esc" and not self.is_top_level(): self.backtrack() return key diff --git a/khal/ui/calendarwidget.py b/khal/ui/calendarwidget.py index 0cc7ed2ba..df7b2c8c7 100644 --- a/khal/ui/calendarwidget.py +++ b/khal/ui/calendarwidget.py @@ -183,7 +183,7 @@ def set_focus_date(self, a_date: dt.date) -> None: for num, day in enumerate(self.contents[1:8], 1): if day[0].date == a_date: self.focus_position = num - return None + return raise ValueError(f"{a_date} not found in this week") def get_date_column(self, a_date: dt.date) -> int: @@ -415,9 +415,7 @@ def set_focus(self, position: int) -> None: def days_to_next_already_loaded(self, day: dt.date) -> int: """return the number of weeks from the focus to the next week that is already loaded""" - if len(self) == 0: - return 0 - elif self.earliest_date <= day <= self.latest_date: + if len(self) == 0 or self.earliest_date <= day <= self.latest_date: return 0 elif day <= self.earliest_date: return (self.earliest_date - day).days @@ -529,10 +527,12 @@ def _construct_week(self, week: list[dt.date]) -> DateCColumns: :param week: list of datetime.date objects :returns: the week as an CColumns object """ - if self.monthdisplay == "firstday" and 1 in (day.day for day in week): - month_name = calendar.month_abbr[week[-1].month].ljust(4) - attr = "monthname" - elif self.monthdisplay == "firstfullweek" and week[0].day <= 7: + if ( + self.monthdisplay == "firstday" + and 1 in (day.day for day in week) + or self.monthdisplay == "firstfullweek" + and week[0].day <= 7 + ): month_name = calendar.month_abbr[week[-1].month].ljust(4) attr = "monthname" elif self.weeknumbers == "left": diff --git a/tests/utils.py b/tests/utils.py index 9c66cd2d2..7d09b5959 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -10,7 +10,7 @@ try: from icalendar.parser import Contentlines # icalendar >= 7.0.0 except ImportError: - from icalendar.cal import Contentlines # icalendar < 7.0.0 # noqa: F401 + from icalendar.cal import Contentlines # icalendar < 7.0.0 CollVdirType = tuple[CalendarCollection, dict[str, Vdir]] diff --git a/tests/utils_test.py b/tests/utils_test.py index 4989b2583..02de4a34d 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -16,11 +16,9 @@ def test_relative_timedelta_str(): assert utils.relative_timedelta_str(dt.date(2016, 7, 29)) == "~7 weeks ago" -weekheader = """ Mo Tu We Th Fr Sa Su """ -today_line = """Today""" -calendarline = ( - "Nov 31  1  2  3  4  5  6" -) +weekheader = """\x1b[1m Mo Tu We Th Fr Sa Su \x1b[0m""" +today_line = """\x1b[1mToday\x1b[0m\x1b[0m""" +calendarline = "\x1b[1mNov \x1b[0m\x1b[1;33m31\x1b[0m \x1b[32m 1\x1b[0m \x1b[1;33m 2\x1b[0m \x1b[1;33m 3\x1b[0m \x1b[1;33m 4\x1b[0m \x1b[32m 5\x1b[0m \x1b[32m 6\x1b[0m" def test_last_reset():