Skip to content

use one line boolean condition with add types #9666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
8 changes: 3 additions & 5 deletions rest_framework/utils/timezone.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timezone, tzinfo
from datetime import timezone, tzinfo


def datetime_exists(dt):
Expand All @@ -9,7 +9,7 @@ def datetime_exists(dt):
return dt.astimezone(timezone.utc) == dt


def datetime_ambiguous(dt: datetime):
def datetime_ambiguous(dt):
"""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.
Expand All @@ -20,6 +20,4 @@ def datetime_ambiguous(dt: datetime):

def valid_datetime(dt):
"""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)
Loading