feat: add the scheduled, deadline and closed arguments to Headline init

style: Improve the type hints of Time

When reading them it's more natural to read Optional[Time] than to
assume that None is part of the Union in Time
This commit is contained in:
Lyz 2024-07-20 11:14:15 +02:00
parent 694f3f59e2
commit f640521b56
No known key found for this signature in database
GPG Key ID: 6C7D7C1612CDE02F

View File

@ -302,6 +302,9 @@ class Headline:
is_todo: bool, is_todo: bool,
is_done: bool, is_done: bool,
spacing, spacing,
scheduled: Optional[Time] = None,
deadline: Optional[Time] = None,
closed: Optional[Time] = None,
): ):
self.start_line = start_line self.start_line = start_line
self.depth = depth self.depth = depth
@ -324,9 +327,9 @@ class Headline:
self.parent = parent self.parent = parent
self.is_todo = is_todo self.is_todo = is_todo
self.is_done = is_done self.is_done = is_done
self.scheduled: Time = None self.scheduled = scheduled
self.deadline: Time = None self.deadline = deadline
self.closed: Time = None self.closed = closed
self.spacing = spacing self.spacing = spacing
# Read planning line # Read planning line
@ -712,7 +715,7 @@ class Headline:
time_seg = content[len("CLOCK:") :].strip() time_seg = content[len("CLOCK:") :].strip()
parsed: Time = None parsed: Optional[Time] = None
if "--" in time_seg: if "--" in time_seg:
# TODO: Consider duration # TODO: Consider duration
start, end = time_seg.split("=")[0].split("--") start, end = time_seg.split("=")[0].split("--")
@ -1522,10 +1525,10 @@ def timestamp_to_string(ts: Timestamp, end_time: Optional[Timestamp] = None) ->
return "[{}]".format(base) return "[{}]".format(base)
Time = Union[None, TimeRange, OrgTime] Time = Union[TimeRange, OrgTime]
def parse_time(value: str) -> Time: def parse_time(value: str) -> Optional[Time]:
if (value.count(">--<") == 1) or (value.count("]--[") == 1): if (value.count(">--<") == 1) or (value.count("]--[") == 1):
# Time ranges with two different dates # Time ranges with two different dates
# @TODO properly consider "=> DURATION" section # @TODO properly consider "=> DURATION" section
@ -2151,7 +2154,9 @@ class OrgDoc:
for keyword in keywords: for keyword in keywords:
if keyword.key in ("TODO", "SEQ_TODO"): if keyword.key in ("TODO", "SEQ_TODO"):
todo_kws, done_kws = re.sub(r"\([^)]+\)", "", keyword.value).split("|", 1) todo_kws, done_kws = re.sub(r"\([^)]+\)", "", keyword.value).split(
"|", 1
)
self.todo_keywords = re.sub(r"\s{2,}", " ", todo_kws.strip()).split() self.todo_keywords = re.sub(r"\s{2,}", " ", todo_kws.strip()).split()
self.done_keywords = re.sub(r"\s{2,}", " ", done_kws.strip()).split() self.done_keywords = re.sub(r"\s{2,}", " ", done_kws.strip()).split()