Skip to content

Commit

Permalink
Add mypy checks
Browse files Browse the repository at this point in the history
  • Loading branch information
llazzaro committed Apr 3, 2022
1 parent 01b58bf commit 11414b7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
3 changes: 2 additions & 1 deletion schedule/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import List, Any
from django import forms
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -43,6 +44,6 @@ class Meta:

class EventAdminForm(forms.ModelForm):
class Meta:
exclude = []
exclude: List[Any] = []
model = Event
widgets = {"color_event": ColorInput}
2 changes: 1 addition & 1 deletion schedule/models/calendars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 6 additions & 7 deletions schedule/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,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()
Expand Down Expand Up @@ -206,7 +206,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):
Expand All @@ -229,7 +229,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)
Expand Down Expand Up @@ -474,7 +474,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
Expand Down Expand Up @@ -604,12 +604,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()
Expand Down
6 changes: 3 additions & 3 deletions schedule/periods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
[tox]
envlist =
lint
django22
mypy
django31
django32
djangomain

[testenv]
commands = {envpython} -Wa -b -m coverage run -m django test --settings=tests.settings
deps =
django22: Django>=2.2,<2.3
django31: Django~=3.1.0
django32: Django~=3.2.0
djangomain: https://github.com/django/django/archive/main.tar.gz
coverage


[testenv:lint]
basepython = python3
commands =
Expand All @@ -27,3 +25,13 @@ deps =
black
flake8
isort>=5.0.2


[testenv:mypy]
basepython = python3
commands =
mypy schedule
deps =
types-python-dateutil
types-pytz
mypy

0 comments on commit 11414b7

Please sign in to comment.