diff --git a/khal/khalendar/event.py b/khal/khalendar/event.py index 58b1499ac..7c3a0bbf2 100644 --- a/khal/khalendar/event.py +++ b/khal/khalendar/event.py @@ -69,7 +69,7 @@ def __init__(self, color: Optional[str] = None, start: Optional[dt.datetime] = None, end: Optional[dt.datetime] = None, - ): + ) -> None: """ :param start: start datetime of this event instance :param end: end datetime of this event instance @@ -769,7 +769,7 @@ class LocalizedEvent(DatetimeEvent): see parent """ - def __init__(self, *args, **kwargs): + def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) try: starttz = getattr(self._vevents[self.ref]['DTSTART'].dt, 'tzinfo', None) diff --git a/khal/khalendar/exceptions.py b/khal/khalendar/exceptions.py index ae903744b..db0c4bc27 100644 --- a/khal/khalendar/exceptions.py +++ b/khal/khalendar/exceptions.py @@ -28,7 +28,7 @@ class UnsupportedRruleExceptionError(UnsupportedFeatureError): """we do not support exceptions that do not delete events yet""" - def __init__(self, message=''): + def __init__(self, message='') -> None: x = 'This kind of recurrence exception is currently unsupported' if message: x += f': {message.strip()}' diff --git a/khal/khalendar/vdir.py b/khal/khalendar/vdir.py index 77022c4b2..2b3e688b8 100644 --- a/khal/khalendar/vdir.py +++ b/khal/khalendar/vdir.py @@ -29,7 +29,7 @@ class cached_property: instances' methods. ''' - def __init__(self, fget, doc=None): + def __init__(self, fget, doc=None) -> None: self.__name__ = fget.__name__ self.__module__ = fget.__module__ self.__doc__ = doc or fget.__doc__ @@ -94,7 +94,7 @@ def get_etag_from_file(f) -> str: class VdirError(IOError): - def __init__(self, *args, **kwargs): + def __init__(self, *args, **kwargs) -> None: for key, value in kwargs.items(): if getattr(self, key, object()) not in [None, '']: # pragma: no cover raise TypeError(f'Invalid argument: {key}') @@ -120,7 +120,7 @@ class AlreadyExistingError(VdirError): class Item: - def __init__(self, raw: str): + def __init__(self, raw: str) -> None: assert isinstance(raw, str) self.raw = raw @@ -145,7 +145,7 @@ class VdirBase: item_class = Item default_mode = 0o750 - def __init__(self, path: str, fileext: str, encoding: str='utf-8'): + def __init__(self, path: str, fileext: str, encoding: str='utf-8') -> None: if not os.path.isdir(path): raise CollectionNotFoundError(path) self.path = path @@ -284,7 +284,7 @@ def set_meta(self, key: str, value: str) -> None: class Color: - def __init__(self, x: str): + def __init__(self, x: str) -> None: if not x: raise ValueError('Color is false-ish.') if not x.startswith('#'): diff --git a/khal/ui/__init__.py b/khal/ui/__init__.py index ebe0a7c3c..b3f111826 100644 --- a/khal/ui/__init__.py +++ b/khal/ui/__init__.py @@ -102,7 +102,7 @@ def render(self, size, focus=False): class DateHeader(SelectableText): - def __init__(self, day: dt.date, dateformat: str, conf): + def __init__(self, day: dt.date, dateformat: str, conf) -> None: """ :param day: the date that is represented by this DateHeader instance :param dateformat: format to print `day` in @@ -154,7 +154,7 @@ def keypress(self, _, key: str) -> str: class U_Event(urwid.Text): - def __init__(self, event, conf, delete_status, this_date=None, relative=True): + def __init__(self, event, conf, delete_status, this_date=None, relative=True) -> None: """representation of an event in EventList :param event: the encapsulated event @@ -239,7 +239,7 @@ def __init__( self, *args, parent, conf, delete_status, toggle_delete_instance, toggle_delete_all, set_focus_date_callback=None, - **kwargs): + **kwargs) -> None: self._init: bool = True self.parent: 'ClassicView' = parent self.delete_status = delete_status @@ -276,7 +276,7 @@ class DListBox(EventListBox): """Container for a DayWalker""" # XXX unfortunate naming, there is also DateListBox - def __init__(self, *args, **kwargs): + def __init__(self, *args, **kwargs) -> None: dynamic_days = kwargs.pop('dynamic_days', True) super().__init__(*args, **kwargs) self._init = dynamic_days @@ -352,7 +352,7 @@ class DayWalker(urwid.SimpleFocusListWalker): """A list Walker that contains a list of DateListBox objects, each representing one day and associated events""" - def __init__(self, this_date, eventcolumn, conf, collection, delete_status): + def __init__(self, this_date, eventcolumn, conf, collection, delete_status) -> None: self.eventcolumn = eventcolumn self._conf = conf self.delete_status = delete_status @@ -577,11 +577,11 @@ class DateListBox(urwid.ListBox): selected_date = None - def __init__(self, content, date): + def __init__(self, content, date) -> None: self.date = date super().__init__(content) - def __repr__(self): + def __repr__(self) -> str: return f'' __str__ = __repr__ @@ -633,7 +633,7 @@ class EventColumn(urwid.WidgetWrap): Handles modifying events, showing events' details and editing them """ - def __init__(self, elistbox, pane): + def __init__(self, elistbox, pane) -> None: self.pane = pane self._conf = pane._conf self.divider = urwid.Divider('─') @@ -955,7 +955,7 @@ def render(self, a, focus): class EventDisplay(urwid.WidgetWrap): """A widget showing one Event()'s details """ - def __init__(self, conf, event, collection=None): + def __init__(self, conf, event, collection=None) -> None: self._conf = conf self.collection = collection self.event = event @@ -1017,7 +1017,7 @@ def __init__(self, conf, event, collection=None): class SearchDialog(urwid.WidgetWrap): """A Search Dialog Widget""" - def __init__(self, search_func, abort_func): + def __init__(self, search_func, abort_func) -> None: class Search(Edit): @@ -1052,7 +1052,7 @@ class ClassicView(Pane): on the right """ - def __init__(self, collection, conf=None, title: str='', description: str=''): + def __init__(self, collection, conf=None, title: str='', description: str='') -> None: self.init = True # Will be set when opening the view inside a Window self.window = None diff --git a/khal/ui/base.py b/khal/ui/base.py index ad5659143..032b0eade 100644 --- a/khal/ui/base.py +++ b/khal/ui/base.py @@ -41,7 +41,7 @@ class Pane(urwid.WidgetWrap): """An abstract Pane to be used in a Window object.""" - def __init__(self, widget, title=None, description=None): + def __init__(self, widget, title=None, description=None) -> None: self.widget = widget urwid.WidgetWrap.__init__(self, widget) self._title = title or '' diff --git a/khal/ui/calendarwidget.py b/khal/ui/calendarwidget.py index 87c7435ad..34b2d9844 100644 --- a/khal/ui/calendarwidget.py +++ b/khal/ui/calendarwidget.py @@ -57,7 +57,7 @@ class DatePart(urwid.Text): """used in the Date widget (single digit)""" - def __init__(self, digit: str): + def __init__(self, digit: str) -> None: super().__init__(digit) @classmethod @@ -82,7 +82,7 @@ class Date(urwid.WidgetWrap): """used in the main calendar for dates (a number)""" - def __init__(self, date: dt.date, get_styles: GetStylesSignature): + def __init__(self, date: dt.date, get_styles: GetStylesSignature) -> None: dstr = str(date.day).rjust(2) self.halves = [urwid.AttrMap(DatePart(dstr[:1]), None, None), urwid.AttrMap(DatePart(dstr[1:]), None, None)] @@ -142,7 +142,7 @@ def __init__(self, on_press: OnPressType, keybindings: Dict[str, List[str]], get_styles: GetStylesSignature, - **kwargs): + **kwargs) -> None: self.on_date_change = on_date_change self.on_press = on_press self.keybindings = keybindings @@ -236,7 +236,7 @@ class CListBox(urwid.ListBox): it should contain a `CalendarWalker` instance which it autoextends on rendering, if needed """ - def __init__(self, walker: 'CalendarWalker'): + def __init__(self, walker: 'CalendarWalker') -> None: self._init: bool = True self.keybindings = walker.keybindings self.on_press = walker.on_press @@ -595,7 +595,7 @@ def __init__(self, monthdisplay: Literal['firstday', 'firstfullweek']='firstday', get_styles: Optional[GetStylesSignature]=None, initial: Optional[dt.date]=None, - ): + ) -> None: """A calendar widget that can be used in urwid applications :param on_date_change: a function that is called every time the selected diff --git a/khal/ui/editor.py b/khal/ui/editor.py index 1063a4dba..fa6498f13 100644 --- a/khal/ui/editor.py +++ b/khal/ui/editor.py @@ -46,7 +46,7 @@ class StartEnd: - def __init__(self, startdate, starttime, enddate, endtime): + def __init__(self, startdate, starttime, enddate, endtime) -> None: """collecting some common properties""" self.startdate = startdate self.starttime = starttime @@ -56,7 +56,7 @@ def __init__(self, startdate, starttime, enddate, endtime): class CalendarPopUp(urwid.PopUpLauncher): def __init__(self, widget, on_date_change, weeknumbers=False, - firstweekday=0, monthdisplay='firstday', keybindings=None): + firstweekday=0, monthdisplay='firstday', keybindings=None) -> None: self._on_date_change = on_date_change self._weeknumbers = weeknumbers self._monthdisplay = monthdisplay @@ -112,7 +112,7 @@ def __init__( firstweekday: int=0, monthdisplay: Literal['firstday', 'firstfullweek']='firstday', keybindings: Optional[Dict[str, List[str]]] = None, - ): + ) -> None: datewidth = len(startdt.strftime(dateformat)) + 1 self._dateformat = dateformat if startdt is None: @@ -161,7 +161,7 @@ def __init__(self, start, end, conf, on_start_date_change=lambda x: None, on_end_date_change=lambda x: None, - ): + ) -> None: """ :type start: datetime.datetime :type end: datetime.datetime @@ -336,7 +336,7 @@ def validate(self): class EventEditor(urwid.WidgetWrap): """Widget that allows Editing one `Event()`""" - def __init__(self, pane, event, save_callback=None, always_save=False): + def __init__(self, pane, event, save_callback=None, always_save=False) -> None: """ :type event: khal.event.Event :param save_callback: call when saving event with new start and end @@ -572,7 +572,7 @@ def keypress(self, size, key): class WeekDaySelector(urwid.WidgetWrap): - def __init__(self, startdt, selected_days): + def __init__(self, startdt, selected_days) -> None: self._weekday_boxes = {day: urwid.CheckBox(day, state=False) for day in WEEKDAYS} weekday = startdt.weekday() @@ -590,7 +590,7 @@ def days(self): class RecurrenceEditor(urwid.WidgetWrap): - def __init__(self, rrule, conf, startdt): + def __init__(self, rrule, conf, startdt) -> None: self._conf = conf self._startdt = startdt self._rrule = rrule @@ -797,7 +797,7 @@ def active(self, val): class ExportDialog(urwid.WidgetWrap): - def __init__(self, this_func, abort_func, event): + def __init__(self, this_func, abort_func, event) -> None: lines = [] lines.append(urwid.Text('Export event as ICS file')) lines.append(urwid.Text('')) diff --git a/khal/ui/widgets.py b/khal/ui/widgets.py index 050269863..7be6413b9 100644 --- a/khal/ui/widgets.py +++ b/khal/ui/widgets.py @@ -124,7 +124,7 @@ def _goto_end_of_line(self): class DateTimeWidget(ExtendedEdit): - def __init__(self, dateformat: str, on_date_change=lambda x: None, **kwargs): + def __init__(self, dateformat: str, on_date_change=lambda x: None, **kwargs) -> None: self.dateformat = dateformat self.on_date_change = on_date_change super().__init__(wrap='any', **kwargs) @@ -202,7 +202,7 @@ def _get_current_value(self): class Choice(urwid.PopUpLauncher): def __init__( self, choices, active, decorate_func=None, overlay_width=32, callback=lambda: None, - ): + ) -> None: self.choices = choices self._callback = callback self._decorate = decorate_func or (lambda x: x) @@ -243,7 +243,7 @@ class ChoiceList(urwid.WidgetWrap): """A pile of Button() widgets, intended to be used with Choice()""" signals = ['close'] - def __init__(self, parent, callback=lambda: None): + def __init__(self, parent, callback=lambda: None) -> None: self.parent = parent self._callback = callback buttons = [] @@ -275,7 +275,7 @@ class SupportsNext: _select_last_selectable """ - def __init__(self, *args, **kwargs): + def __init__(self, *args, **kwargs) -> None: self.outermost = kwargs.get('outermost', False) if 'outermost' in kwargs: kwargs.pop('outermost') @@ -398,7 +398,7 @@ def keypress(self, size, key): class ValidatedEdit(urwid.WidgetWrap): - def __init__(self, *args, EditWidget=ExtendedEdit, validate=False, **kwargs): + def __init__(self, *args, EditWidget=ExtendedEdit, validate=False, **kwargs) -> None: assert validate self._validate_func = validate self._original_widget = urwid.AttrMap(EditWidget(*args, **kwargs), 'edit', 'edit focused') @@ -446,7 +446,7 @@ def keypress(self, size, key): class PositiveIntEdit(ValidatedEdit): - def __init__(self, *args, EditWidget=ExtendedEdit, validate=False, **kwargs): + def __init__(self, *args, EditWidget=ExtendedEdit, validate=False, **kwargs) -> None: """Variant of Validated Edit that only accepts positive integers.""" super().__init__(*args, validate=self._unsigned_int, **kwargs) @@ -478,7 +478,7 @@ def _convert_timedelta(dt): seconds = int(seconds % 60) return days, hours, minutes, seconds - def __init__(self, dt): + def __init__(self, dt) -> None: days, hours, minutes, seconds = self._convert_timedelta(dt) self.days_edit = ValidatedEdit( @@ -515,7 +515,7 @@ class AlarmsEditor(urwid.WidgetWrap): class AlarmEditor(urwid.WidgetWrap): - def __init__(self, alarm, delete_handler): + def __init__(self, alarm, delete_handler) -> None: duration, description = alarm if duration.total_seconds() > 0: direction = 'after' @@ -546,7 +546,7 @@ def get_alarm(self): prefix = 1 return (prefix * self.duration.get_timedelta(), self.description.get_edit_text()) - def __init__(self, event): + def __init__(self, event) -> None: self.event = event self.pile = NPile( @@ -581,7 +581,7 @@ def changed(self): class FocusLineBoxWidth(urwid.WidgetDecoration, urwid.WidgetWrap): - def __init__(self, widget): + def __init__(self, widget) -> None: hline = urwid.Divider('─') hline_focus = urwid.Divider('━') self._vline = urwid.SolidFill('│') @@ -634,7 +634,7 @@ def render(self, size, focus): class FocusLineBoxColor(urwid.WidgetDecoration, urwid.WidgetWrap): - def __init__(self, widget): + def __init__(self, widget) -> None: hline = urwid.Divider('─') self._vline = urwid.AttrMap(urwid.SolidFill('│'), 'frame') self._topline = urwid.AttrMap( @@ -677,7 +677,7 @@ def render(self, size, focus): class FocusLineBoxTop(urwid.WidgetDecoration, urwid.WidgetWrap): - def __init__(self, widget): + def __init__(self, widget) -> None: topline = urwid.AttrMap(urwid.Divider('━'), 'frame') self._all = urwid.Pile([('flow', topline), widget], focus_item=1) urwid.WidgetWrap.__init__(self, self._all) diff --git a/khal/utils.py b/khal/utils.py index ef13edd58..cac1226ef 100644 --- a/khal/utils.py +++ b/khal/utils.py @@ -31,6 +31,7 @@ from typing import Iterator, List, Optional, Tuple import pytz +import urwid def generate_random_uid() -> str: @@ -177,5 +178,5 @@ def relative_timedelta_str(day: dt.date) -> str: return f'{approx}{count} {unit} {direction}' -def get_wrapped_text(widget): +def get_wrapped_text(widget: urwid.AttrMap) -> str: return widget.original_widget.get_edit_text() diff --git a/tests/cli_test.py b/tests/cli_test.py index 3b0fb50b4..f2b827103 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -14,7 +14,7 @@ class CustomCliRunner(CliRunner): def __init__(self, config_file, db=None, calendars=None, - xdg_data_home=None, xdg_config_home=None, tmpdir=None, **kwargs): + xdg_data_home=None, xdg_config_home=None, tmpdir=None, **kwargs) -> None: self.config_file = config_file self.db = db self.calendars = calendars diff --git a/tests/utils.py b/tests/utils.py index cfcf636a9..14b4e317a 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -136,6 +136,6 @@ def _replace_uid(event): class DumbItem: - def __init__(self, raw, uid): + def __init__(self, raw, uid) -> None: self.raw = raw self.uid = uid