Skip to content

Commit

Permalink
fix datetime module detection
Browse files Browse the repository at this point in the history
  • Loading branch information
pjknkda committed Apr 25, 2019
1 parent 90e1144 commit b8894e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Empty file removed .flake8
Empty file.
17 changes: 12 additions & 5 deletions flake8_datetimez.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b8894e4

Please sign in to comment.