diff options
author | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-06-25 23:42:10 +0300 |
---|---|---|
committer | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-06-25 23:42:10 +0300 |
commit | dde7afa51359b0a51b0a336a3dfbce4da0d719ee (patch) | |
tree | 4c8c7793d55e2f6e41e249477a3e056f4875e7d3 /pylint/checkers | |
parent | 8f550e18295a573a4e9a106cd9af3cac944af7c6 (diff) | |
download | pylint-dde7afa51359b0a51b0a336a3dfbce4da0d719ee.tar.gz |
Add a new error for the Python 3 porting checker, `import-star-module-level`.
This error is used when a star import is detected in another scope than the
module level, which is an error on Python 3. Using this will emit a
SyntaxWarning on Python 2.
Diffstat (limited to 'pylint/checkers')
-rw-r--r-- | pylint/checkers/python3.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py index 95aa3a7..6738ec6 100644 --- a/pylint/checkers/python3.py +++ b/pylint/checkers/python3.py @@ -130,6 +130,11 @@ class Python3Checker(checkers.BaseChecker): {'scope': WarningScope.NODE, 'maxversion': (3, 0), 'old_names': [('W0333', 'backtick')]}), + 'E1609': ('Import * only allowed at module level', + 'import-star-module-level', + 'Used when the import star syntax is used somewhere ' + 'else than the module level.', + {'maxversion': (3, 0)}), 'W1601': ('apply built-in referenced', 'apply-builtin', 'Used when the apply built-in function is referenced ' @@ -403,7 +408,7 @@ class Python3Checker(checkers.BaseChecker): def visit_print(self, node): self.add_message('print-statement', node=node) - @utils.check_messages('no-absolute-import') + @utils.check_messages('no-absolute-import', 'import-star-module-level') def visit_from(self, node): if node.modname == '__future__': for name, _ in node.names: @@ -413,6 +418,9 @@ class Python3Checker(checkers.BaseChecker): self._future_absolute_import = True elif not self._future_absolute_import: self.add_message('no-absolute-import', node=node) + if node.names[0][0] == '*': + if not isinstance(node.scope(), astroid.Module): + self.add_message('import-star-module-level', node=node) @utils.check_messages('no-absolute-import') def visit_import(self, node): |