Skip to content

Commit 26fde1d

Browse files
committed
Use shared compact_dict helper for sync/async param building
Add a pure compact_dict helper and reuse it across TodoistAPI and TodoistAPIAsync to reduce duplicated None-filtering logic in request params/data preparation.
1 parent 80c4832 commit 26fde1d

3 files changed

Lines changed: 275 additions & 448 deletions

File tree

todoist_api_python/_core/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import uuid
55
from datetime import date, datetime, timezone
6+
from typing import TypeVar
67

78
if sys.version_info >= (3, 11):
89
from datetime import UTC
@@ -43,6 +44,14 @@ def parse_datetime(datetime_str: str) -> datetime:
4344
return datetime.fromisoformat(datetime_str)
4445

4546

47+
V = TypeVar("V")
48+
49+
50+
def compact_dict(**values: V | None) -> dict[str, V]:
51+
"""Return a dictionary without keys whose value is `None`."""
52+
return {key: value for key, value in values.items() if value is not None}
53+
54+
4655
def default_request_id_fn() -> str:
4756
"""Generate random UUIDv4s as the default request ID."""
4857
return str(uuid.uuid4())

0 commit comments

Comments
 (0)