- one line boolean condition

- add types
This commit is contained in:
ArtemIsmagilov 2025-03-17 12:26:46 +04:00
parent 73cbb9cd4a
commit c74365117e

View File

@ -1,7 +1,7 @@
from datetime import datetime, timezone, tzinfo
def datetime_exists(dt):
def datetime_exists(dt: datetime) -> bool:
"""Check if a datetime exists. Taken from: https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html"""
# There are no non-existent times in UTC, and comparisons between
# aware time zones always compare absolute times; if a datetime is
@ -9,7 +9,7 @@ def datetime_exists(dt):
return dt.astimezone(timezone.utc) == dt
def datetime_ambiguous(dt: datetime):
def datetime_ambiguous(dt: datetime) -> bool:
"""Check whether a datetime is ambiguous. Taken from: https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html"""
# If a datetime exists and its UTC offset changes in response to
# changing `fold`, it is ambiguous in the zone specified.
@ -18,8 +18,6 @@ def datetime_ambiguous(dt: datetime):
)
def valid_datetime(dt):
def valid_datetime(dt: datetime) -> bool:
"""Returns True if the datetime is not ambiguous or imaginary, False otherwise."""
if isinstance(dt.tzinfo, tzinfo) and not datetime_ambiguous(dt):
return True
return False
return isinstance(dt.tzinfo, tzinfo) and not datetime_ambiguous(dt)