From c74365117ed6e1d0393954173248cbfa4bb4298d Mon Sep 17 00:00:00 2001 From: ArtemIsmagilov Date: Mon, 17 Mar 2025 12:26:46 +0400 Subject: [PATCH] - one line boolean condition - add types --- rest_framework/utils/timezone.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/rest_framework/utils/timezone.py b/rest_framework/utils/timezone.py index 3257c8e27..364d9b322 100644 --- a/rest_framework/utils/timezone.py +++ b/rest_framework/utils/timezone.py @@ -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)