Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Commit

Permalink
Fix #31, false positive with 'input' as variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwager committed Nov 5, 2019
1 parent b1cf1f3 commit 0bf7121
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- False positive with 'input' as variable name ([#31](https://github.com/duo-labs/dlint/issues/31))

## [0.9.0] - 2019-10-13
### Added
Expand Down
6 changes: 4 additions & 2 deletions dlint/linters/bad_input_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
unicode_literals,
)

import ast
import sys

from . import base
Expand All @@ -27,12 +28,13 @@ def __init__(self, *args, **kwargs):

super(BadInputUseLinter, self).__init__(*args, **kwargs)

def visit_Name(self, node):
def visit_Call(self, node):
is_python_2 = sys.version_info < (3, 0)

if (is_python_2
and self.unsafe_input_import
and node.id == 'input'):
and isinstance(node.func, ast.Name)
and node.func.id == 'input'):
self.results.append(
base.Flake8Result(
lineno=node.lineno,
Expand Down
15 changes: 15 additions & 0 deletions tests/test_bad_input_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ def test_no_input_usage(self):

assert result == expected

def test_bad_input_variable_usage(self):
python_node = self.get_ast_node(
"""
input = 1
"""
)

linter = dlint.linters.BadInputUseLinter()
linter.visit(python_node)

result = linter.get_results()
expected = []

assert result == expected


if __name__ == "__main__":
unittest.main()

0 comments on commit 0bf7121

Please sign in to comment.