From 922ac20f81db0760eb9d7f8b2bb9e7707873960f Mon Sep 17 00:00:00 2001 From: Leonardo Lazzaro Date: Sun, 3 Apr 2022 19:59:15 +0200 Subject: [PATCH] Add mypy checks --- schedule/forms.py | 3 ++- schedule/models/calendars.py | 2 +- schedule/models/events.py | 13 ++++++------- schedule/periods.py | 6 +++--- tox.ini | 11 +++++++++++ 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/schedule/forms.py b/schedule/forms.py index d548b279..3979a713 100644 --- a/schedule/forms.py +++ b/schedule/forms.py @@ -1,3 +1,4 @@ +from typing import List, Any from django import forms from django.utils.translation import gettext_lazy as _ @@ -43,6 +44,6 @@ class Meta: class EventAdminForm(forms.ModelForm): class Meta: - exclude = [] + exclude: List[Any] = [] model = Event widgets = {"color_event": ColorInput} diff --git a/schedule/models/calendars.py b/schedule/models/calendars.py index 81f8a7de..2ea0b62d 100644 --- a/schedule/models/calendars.py +++ b/schedule/models/calendars.py @@ -183,7 +183,7 @@ def get_absolute_url(self): class CalendarRelationManager(models.Manager): def create_relation( - self, calendar, content_object, distinction="", inheritable=True + self, calendar, content_object, distinction: str = "", inheritable: bool = True ): """ Creates a relation between calendar and content_object. diff --git a/schedule/models/events.py b/schedule/models/events.py index 010d5345..7ced9fb4 100644 --- a/schedule/models/events.py +++ b/schedule/models/events.py @@ -116,7 +116,7 @@ def hours(self): def get_absolute_url(self): return reverse("event", args=[self.id]) - def get_occurrences(self, start, end, clear_prefetch=True): + def get_occurrences(self, start: datetime.datetime, end: datetime.datetime, clear_prefetch: bool = True): """ >>> rule = Rule(frequency = "MONTHLY", name = "Monthly") >>> rule.save() @@ -205,7 +205,7 @@ def _create_occurrence(self, start, end=None): event=self, start=start, end=end, original_start=start, original_end=end ) - def get_occurrence(self, date): + def get_occurrence(self, date: datetime.datetime): use_naive = timezone.is_naive(date) tzinfo = timezone.utc if timezone.is_naive(date): @@ -228,7 +228,7 @@ def get_occurrence(self, date): next_occurrence = timezone.make_naive(next_occurrence, tzinfo) return self._create_occurrence(next_occurrence) - def _get_occurrence_list(self, start, end): + def _get_occurrence_list(self, start: datetime.datetime, end: datetime.datetime): """ Returns a list of occurrences that fall completely or partially inside the timespan defined by start (inclusive) and end (exclusive) @@ -473,7 +473,7 @@ class EventRelationManager(models.Manager): # eventrelation__event = event # ) - def get_events_for_object(self, content_object, distinction="", inherit=True): + def get_events_for_object(self, content_object, distinction: str = "", inherit: bool = True): """ returns a queryset full of events, that relate to the object through, the distinction @@ -603,12 +603,11 @@ def __init__(self, *args, **kwargs): if not self.description and self.event_id: self.description = self.event.description + @property def moved(self): return self.original_start != self.start or self.original_end != self.end - moved = property(moved) - - def move(self, new_start, new_end): + def move(self, new_start: datetime.datetime, new_end: datetime.datetime): self.start = new_start self.end = new_end self.save() diff --git a/schedule/periods.py b/schedule/periods.py index 9ca5d922..e2cc33dc 100644 --- a/schedule/periods.py +++ b/schedule/periods.py @@ -117,7 +117,7 @@ def get_persisted_occurrences(self): ) return self._persisted_occurrences - def classify_occurrence(self, occurrence): + def classify_occurrence(self, occurrence: Occurrence): if occurrence.cancelled and not SHOW_CANCELLED_OCCURRENCES: return if occurrence.start > self.end or occurrence.end < self.start: @@ -152,12 +152,12 @@ def get_occurrences(self): def has_occurrences(self): return any(self.classify_occurrence(o) for o in self.occurrences) - def get_time_slot(self, start, end): + def get_time_slot(self, start: datetime.datetime, end: datetime.datetime): if start >= self.start and end <= self.end: return Period(self.events, start, end, tzinfo=self.tzinfo) return Period([], start, end, tzinfo=self.tzinfo) - def create_sub_period(self, cls, start=None, tzinfo=None): + def create_sub_period(self, cls, start: datetime.datetime = None, tzinfo=None): if tzinfo is None: tzinfo = self.tzinfo start = start or self.start diff --git a/tox.ini b/tox.ini index 779ce27b..5f7f56b4 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,7 @@ deps = # djangomain: https://github.com/django/django/archive/main.tar.gz coverage + [testenv:lint] basepython = python3 commands = @@ -27,3 +28,13 @@ deps = black flake8 isort>=5.0.2 + + +[testenv:mypy] +basepython = python3 +commands = + mypy schedule +deps = + types-python-dateutil + types-pytz + mypy \ No newline at end of file