Skip to content

Commit

Permalink
Add some auto-generated type-hints
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyNotHugo committed Sep 26, 2023
1 parent f174125 commit be4b385
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 48 deletions.
4 changes: 2 additions & 2 deletions khal/khalendar/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion khal/khalendar/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}'
Expand Down
10 changes: 5 additions & 5 deletions khal/khalendar/vdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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}')
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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('#'):
Expand Down
22 changes: 11 additions & 11 deletions khal/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'<DateListBox {self.date}>'

__str__ = __repr__
Expand Down Expand Up @@ -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('─')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion khal/ui/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down
10 changes: 5 additions & 5 deletions khal/ui/calendarwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions khal/ui/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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(''))
Expand Down
Loading

0 comments on commit be4b385

Please sign in to comment.