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

Commit

Permalink
Fix #14, false positive when bad module attribute not imported
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwager committed Aug 24, 2019
1 parent 31e984d commit fa4db6c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- False positive when bad builtin is overwritten by import ([#16](https://github.com/duo-labs/dlint/issues/16))
- False negative when bad module attribute uses import alias ([#2](https://github.com/duo-labs/dlint/issues/2))
- False positive when bad module attribute not imported ([#14](https://github.com/duo-labs/dlint/issues/14))

## [0.6.0] - 2019-08-12
### Added
Expand Down
4 changes: 3 additions & 1 deletion dlint/linters/helpers/bad_module_attribute_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def visit_Attribute(self, node):

def illegal_module(mod):
return (
module_path == mod
# Assuming you can't have a period ('.') in names brought
# into a module's namespace
(module_path == mod and (self.namespace.name_imported(mod) or '.' in mod))
or module_path in self.illegal_import_aliases
)

Expand Down
21 changes: 21 additions & 0 deletions tests/test_helpers/test_bad_module_attribute_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,27 @@ def test_bad_module_class_use(self):

assert result == expected

def test_module_attribute_missing_import_usage(self):
python_node = self.get_ast_node(
"""
import baz
from qux import quine
var = 'echo "TEST"'
foo = None
foo.bar(var)
"""
)

linter = get_bad_module_attribute_use_implementation({'foo': ['bar']})
linter.visit(python_node)

result = linter.get_results()
expected = []

assert result == expected


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

0 comments on commit fa4db6c

Please sign in to comment.