From 6b8b4de21e8327fbbfb0b986d3f6e2aa913e44af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Sun, 5 Jun 2022 23:32:32 +0200 Subject: [PATCH] Use Optional for types that might be None. --- org_rw/org_rw.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/org_rw/org_rw.py b/org_rw/org_rw.py index e3dca6d..987bf37 100644 --- a/org_rw/org_rw.py +++ b/org_rw/org_rw.py @@ -8,7 +8,7 @@ import re import sys from datetime import date, datetime, timedelta from enum import Enum -from typing import Generator, List, Tuple, Union +from typing import Generator, List, Optional, Tuple, Union from . import dom @@ -779,7 +779,7 @@ class Timestamp: self.minute = minute self.repetition = repetition - def to_datetime(self) -> Union[datetime, date]: + def to_datetime(self) -> datetime: if self.hour is not None: return datetime(self.year, self.month, self.day, self.hour, self.minute) else: @@ -955,7 +955,7 @@ def parse_org_time_range(start, end) -> TimeRange: class OrgTime: - def __init__(self, ts: Timestamp, end_time: Union[Timestamp, None] = None): + def __init__(self, ts: Timestamp, end_time: Optional[Timestamp] = None): assert ts is not None self.time = ts self.end_time = end_time @@ -1035,7 +1035,7 @@ def timerange_to_string(tr: TimeRange): return tr.start_time.to_raw() + "--" + tr.end_time.to_raw() -def timestamp_to_string(ts: Timestamp, end_time: Union[Timestamp, None] = None) -> str: +def timestamp_to_string(ts: Timestamp, end_time: Optional[Timestamp] = None) -> str: date = "{year}-{month:02d}-{day:02d}".format( year=ts.year, month=ts.month, day=ts.day )