Skip to content

Commit 259703b

Browse files
committed
chore: deal with code review concerns
1 parent 3c0fa51 commit 259703b

4 files changed

Lines changed: 12 additions & 23 deletions

File tree

caldav/async_davclient.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def auth_flow(self, request):
7272
from caldav.lib import error
7373
from caldav.lib.python_utilities import to_wire
7474
from caldav.lib.url import URL
75-
7675
from caldav.requests import HTTPBearerAuth
7776
from caldav.response import CalendarQueryResult, DAVResponse, PropfindResult
7877

caldav/davobject.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ def is_async_client(self) -> bool:
107107
"""
108108
if self.client is None:
109109
return False
110-
# Use string check to avoid circular imports
111-
return type(self.client).__name__ == "AsyncDAVClient"
110+
from caldav.async_davclient import AsyncDAVClient
111+
112+
return isinstance(self.client, AsyncDAVClient)
112113

113114
def children(
114115
self, type: str | None = None

caldav/response.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def _parse_response(self, response: _Element) -> tuple[str, list[_Element], Any
470470
error.assert_(status)
471471
self.validate_status(status)
472472
elif elem.tag == dav.Href.tag:
473-
assert not href
473+
error.assert_(not href)
474474
href = _normalize_href(elem.text or "")
475475
elif elem.tag == dav.PropStat.tag:
476476
propstats.append(elem)
@@ -507,8 +507,6 @@ def _parse_scheduling_response_objects(self, parent) -> dict:
507507
attendee - potentially with error status for all or some
508508
of the wanted attendees.
509509
510-
TODO: some asserts here - should make better error handling
511-
512510
Returns:
513511
Dict with:
514512
* email addresses -> FreeBusy status (raw data)
@@ -517,9 +515,9 @@ def _parse_scheduling_response_objects(self, parent) -> dict:
517515
"""
518516
self.objects = {}
519517
self.objects["errors"] = {}
520-
assert self.tree.tag == cdav.ScheduleResponse.tag
518+
error.assert_(self.tree.tag == cdav.ScheduleResponse.tag)
521519
for response in self.tree:
522-
assert response.tag == cdav.Response.tag
520+
error.assert_(response.tag == cdav.Response.tag)
523521
parsed_response = self._parse_scheduling_response(response)
524522
for x in parsed_response:
525523
if x.endswith(":err"):
@@ -531,8 +529,6 @@ def _parse_scheduling_response_objects(self, parent) -> dict:
531529

532530
def _parse_scheduling_response(self, response) -> dict[str, str]:
533531
"""
534-
TODO: lots of asserts here - should make better error handling
535-
536532
Parses one attendee response from a RFC6638 freebusy scheduling request
537533
538534
Returns:
@@ -547,7 +543,7 @@ def _parse_scheduling_response(self, response) -> dict[str, str]:
547543
for x in response:
548544
if x.tag == cdav.Recipient.tag:
549545
if len(x) == 1:
550-
assert x[0].tag == dav.Href.tag
546+
error.assert_(x[0].tag == dav.Href.tag)
551547
recipient = x[0].text
552548
else:
553549
recipient = x.text
@@ -557,8 +553,8 @@ def _parse_scheduling_response(self, response) -> dict[str, str]:
557553
calendar_data = x.text
558554
else:
559555
raise error.DAVError(f"unexpected attribute {x.tag}")
560-
assert recipient
561-
assert status
556+
error.assert_(recipient)
557+
error.assert_(status)
562558
if not status.startswith("2.0"):
563559
ret[f"{recipient}:err"] = status
564560
if calendar_data:

tests/test_caldav_unit.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,10 +1995,7 @@ def test_get_object_by_uid_returns_coroutine_for_async_client(self):
19951995

19961996
xml_response = self._make_multistatus(ev1)
19971997
client = MockedDAVClient(xml_response)
1998-
# Pretend the client is async by patching the type name
1999-
client.__class__ = type(
2000-
"AsyncDAVClient", (MockedDAVClient,), {"__module__": AsyncDAVClient.__module__}
2001-
)
1998+
client.__class__ = type("MockedAsyncDAVClient", (MockedDAVClient, AsyncDAVClient), {})
20021999
calendar = Calendar(client, url="/calendar/")
20032000
assert calendar.is_async_client
20042001
uid = "20010712T182145Z-123401@example.com"
@@ -2016,9 +2013,7 @@ def test_get_object_by_uid_async_returns_correct_object(self):
20162013
from caldav.async_davclient import AsyncDAVClient
20172014

20182015
client = MockedDAVClient("")
2019-
client.__class__ = type(
2020-
"AsyncDAVClient", (MockedDAVClient,), {"__module__": AsyncDAVClient.__module__}
2021-
)
2016+
client.__class__ = type("MockedAsyncDAVClient", (MockedDAVClient, AsyncDAVClient), {})
20222017
calendar = Calendar(client, url="/calendar/")
20232018
uid = "20010712T182145Z-123401@example.com"
20242019

@@ -2072,9 +2067,7 @@ def _make_async_client_and_calendar(self):
20722067
from caldav.async_davclient import AsyncDAVClient
20732068

20742069
client = MockedDAVClient("")
2075-
client.__class__ = type(
2076-
"AsyncDAVClient", (MockedDAVClient,), {"__module__": AsyncDAVClient.__module__}
2077-
)
2070+
client.__class__ = type("MockedAsyncDAVClient", (MockedDAVClient, AsyncDAVClient), {})
20782071
calendar = Calendar(client, url="/calendar/")
20792072
return client, calendar
20802073

0 commit comments

Comments
 (0)