Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions flake8_datetimez.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ def visit_Call(self, node):
if (is_datetime_class and node.func.attr == 'datetime') or is_unqualified_datetime_class_call:
# ex `datetime(2000, 1, 1, 0, 0, 0, 0, datetime.timezone.utc)`
is_case_1 = (len(node.args) == 8
and not (isinstance(node.args[7], ast.NameConstant)
and not (isinstance(node.args[7], ast.Constant)
and node.args[7].value is None))

# ex `datetime.datetime(2000, 1, 1, tzinfo=datetime.timezone.utc)`
tzinfo_keyword = _get_from_keywords(node.keywords, 'tzinfo')
is_case_2 = (tzinfo_keyword is not None
and not (isinstance(tzinfo_keyword.value, ast.NameConstant)
and not (isinstance(tzinfo_keyword.value, ast.Constant)
and tzinfo_keyword.value.value is None))

if not (is_case_1 or is_case_2):
Expand All @@ -97,13 +97,13 @@ def visit_Call(self, node):
# ex: `datetime.now(UTC)`
is_case_1 = (len(node.args) == 1
and len(node.keywords) == 0
and not (isinstance(node.args[0], ast.NameConstant)
and not (isinstance(node.args[0], ast.Constant)
and node.args[0].value is None))

# ex: `datetime.now(tz=UTC)`
tz_keyword = _get_from_keywords(node.keywords, 'tz')
is_case_2 = (tz_keyword is not None
and not (isinstance(tz_keyword.value, ast.NameConstant)
and not (isinstance(tz_keyword.value, ast.Constant)
and tz_keyword.value.value is None))

if not (is_case_1 or is_case_2):
Expand All @@ -113,13 +113,13 @@ def visit_Call(self, node):
# ex: `datetime.fromtimestamp(1234, UTC)`
is_case_1 = (len(node.args) == 2
and len(node.keywords) == 0
and not (isinstance(node.args[1], ast.NameConstant)
and not (isinstance(node.args[1], ast.Constant)
and node.args[1].value is None))

# ex: `datetime.fromtimestamp(1234, tz=UTC)`
tz_keyword = _get_from_keywords(node.keywords, 'tz')
is_case_2 = (tz_keyword is not None
and not (isinstance(tz_keyword.value, ast.NameConstant)
and not (isinstance(tz_keyword.value, ast.Constant)
and tz_keyword.value.value is None))

if not (is_case_1 or is_case_2):
Expand All @@ -138,7 +138,7 @@ def visit_Call(self, node):
else:
tzinfo_keyword = _get_from_keywords(pparent.keywords, 'tzinfo')
is_case_1 = (tzinfo_keyword is not None
and not (isinstance(tzinfo_keyword.value, ast.NameConstant)
and not (isinstance(tzinfo_keyword.value, ast.Constant)
and tzinfo_keyword.value.value is None))

# ex: `datetime.strptime(...).astimezone()`
Expand Down