From b8894e46062847c86cb7b5252d2fc637f8ab3a09 Mon Sep 17 00:00:00 2001 From: Jungkook Park Date: Thu, 25 Apr 2019 18:48:46 +0000 Subject: [PATCH] fix datetime module detection --- .flake8 | 0 flake8_datetimez.py | 17 ++++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index e69de29..0000000 diff --git a/flake8_datetimez.py b/flake8_datetimez.py index 7fbd160..2366963 100644 --- a/flake8_datetimez.py +++ b/flake8_datetimez.py @@ -45,10 +45,17 @@ def __init__(self): self.errors = [] def visit_Call(self, node): - is_datetime_class = (isinstance(node.func.value, ast.Name) + # ex: `datetime.something()`` + is_datetime_class = (isinstance(node.func, ast.Attribute) + and isinstance(node.func.value, ast.Name) and node.func.value.id == 'datetime') - is_datetime_module_n_class = (isinstance(node.func.value, ast.Attribute) - and node.func.value.attr == 'datetime') + + # ex: `datetime.datetime.something()`` + is_datetime_module_n_class = (isinstance(node.func, ast.Attribute) + and isinstance(node.func.value, ast.Attribute) + and node.func.value.attr == 'datetime' + and isinstance(node.func.value.value, ast.Name) + and node.func.value.value.id == 'datetime') if is_datetime_class or is_datetime_module_n_class: if node.func.attr == 'utcnow': @@ -109,8 +116,8 @@ def visit_Call(self, node): self.generic_visit(node) -error = namedtuple('error', ['lineno', 'col', 'message', 'type', 'vars']) -Error = partial(partial, error, type=DateTimeZChecker, vars=()) +error = namedtuple('error', ['lineno', 'col', 'message', 'type']) +Error = partial(partial, error, type=DateTimeZChecker) DTZ001 = Error(