diff --git a/caldav/objects.py b/caldav/objects.py index 2362d9fe..3c758dfe 100644 --- a/caldav/objects.py +++ b/caldav/objects.py @@ -31,7 +31,7 @@ class hierarchy into a separate file) from urllib import unquote, quote try: - from typing import Union, Optional + from typing import ClassVar, Union, Optional TimeStamp = Optional[Union[date, datetime]] except: @@ -1709,6 +1709,12 @@ class CalendarObjectResource(DAVObject): event, a todo-item, a journal entry, or a free/busy entry """ + RELTYPE_REVERSER: ClassVar = { + "PARENT": "CHILD", + "CHILD": "PARENT", + "SIBLING": "SIBLING", + } + _ENDPARAM = None _vobject_instance = None @@ -1811,9 +1817,6 @@ def set_relation( """ ##TODO: test coverage reltype = reltype.upper() - reltype_reverse = {"CHILD": "PARENT", "PARENT": "CHILD", "SIBLING": "SIBLING"}[ - reltype - ] if isinstance(other, CalendarObjectResource): if other.id: uid = other.id @@ -1824,6 +1827,7 @@ def set_relation( if set_reverse: other = self.parent.object_by_uid(uid) if set_reverse: + reltype_reverse = self.RELTYPE_REVERSER[reltype] other.set_relation(other=self, reltype=reltype_reverse, set_reverse=False) existing_relation = self.icalendar_component.get("related-to", None)