Skip to content

Commit

Permalink
Added adherence to mypy requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
dabrows committed Dec 18, 2023
1 parent a223017 commit 70d8b86
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions khal/khalendar/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,21 +522,21 @@ def attendees(self) -> str:

def update_attendees(self, attendees: List[str]):
assert isinstance(attendees, list)
attendees = [Attendee(a) for a in attendees if a != ""]
if len(attendees) > 0:
attendees_o : List[Attendee] = [Attendee(a) for a in attendees if a != ""]
if len(attendees_o) > 0:
# first check for overlaps in existing attendees.
# Existing vCalAddress objects will be copied, non-existing
# vCalAddress objects will be created and appended.
old_attendees = self._vevents[self.ref].get('ATTENDEE', [])
unchanged_attendees = []
vCalAddresses = []
for attendee in attendees:
for attendee in attendees_o:
for old_attendee in old_attendees:
old_email = old_attendee.lstrip("MAILTO:").lower()
if attendee.mail == old_email:
vCalAddresses.append(old_attendee)
unchanged_attendees.append(attendee)
for attendee in [a for a in attendees if a not in unchanged_attendees]:
for attendee in [a for a in attendees_o if a not in unchanged_attendees]:
item = icalendar.prop.vCalAddress(f'MAILTO:{attendee.mail}')
if attendee.cn is not None:
item.params['CN'] = attendee.cn
Expand Down
10 changes: 5 additions & 5 deletions khal/khalendar/khalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self,

self.hmethod = hmethod
self.default_color = default_color
self.default_contacts = []
self.default_contacts : List[str] = []
self.multiple = multiple
self.multiple_on_overflow = multiple_on_overflow
self.color = color
Expand All @@ -112,8 +112,8 @@ def __init__(self,
self._backend = backend.SQLiteDb(self.names, dbpath, self._locale)
self._last_ctags: Dict[str, str] = {}
self.update_db()
for calendar in self._calendars.keys():
self._contacts_update(calendar)
for cname in self._calendars.keys():
self._contacts_update(cname)

@property
def writable_names(self) -> List[str]:
Expand Down Expand Up @@ -369,9 +369,9 @@ def _needs_update(self, calendar: str, remember: bool=False) -> bool:
return local_ctag != self._backend.get_ctag(calendar)

def _contacts_update(self, calendar: str) -> None:
adaptercommand = self._calendars[calendar].get('address_adapter')
if adaptercommand is None:
if self._calendars[calendar].get('address_adapter') is None:
self._contacts[calendar] = []
adaptercommand = str(self._calendars[calendar].get('address_adapter'))
if adaptercommand == "default":
self._contacts[calendar] = self.default_contacts
else:
Expand Down
6 changes: 4 additions & 2 deletions tests/event_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ def test_event_attendees():
assert str(event._vevents[event.ref].get('ATTENDEE', [])[0]) == "MAILTO:[email protected]"

event.update_attendees(["[email protected]", "[email protected]"])
assert event.attendees == "[email protected] <[email protected]>, [email protected] <[email protected]>"
assert event.attendees == "[email protected] <[email protected]>, " \
"[email protected] <[email protected]>"

assert isinstance(event._vevents[event.ref].get('ATTENDEE', []), list)
assert len(event._vevents[event.ref].get('ATTENDEE', [])) == 2
Expand All @@ -561,7 +562,8 @@ def test_event_attendees():
)
event._vevents[event.ref]['ATTENDEE'] = [new_address, ]
event.update_attendees(["[email protected]", "[email protected]"])
assert event.attendees == "Real Name <[email protected]>, [email protected] <[email protected]>"
assert event.attendees == "Real Name <[email protected]>, "\
"[email protected] <[email protected]>"
address = [a for a in event._vevents[event.ref].get('ATTENDEE', [])
if str(a) == "MAILTO:[email protected]"]
assert len(address) == 1
Expand Down

0 comments on commit 70d8b86

Please sign in to comment.