diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2014-01-17 22:58:04 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2014-01-17 22:58:04 +0200 |
commit | 807640def79fb19e7d215ad87adff5b8987b1835 (patch) | |
tree | 4bbb97e106a3e7a193e241d8b05c8c4cd7be0754 /checkers | |
parent | baf09d25e4fe7ccb3bd49cab5d4a27c2cc97dcb4 (diff) | |
parent | 842ee1710db77e200b248f29f66df5707527e82f (diff) | |
download | pylint-807640def79fb19e7d215ad87adff5b8987b1835.tar.gz |
Merged default into all_false_positive
Diffstat (limited to 'checkers')
-rw-r--r-- | checkers/imports.py | 4 | ||||
-rw-r--r-- | checkers/variables.py | 25 |
2 files changed, 26 insertions, 3 deletions
diff --git a/checkers/imports.py b/checkers/imports.py index b0a9872..b3cea23 100644 --- a/checkers/imports.py +++ b/checkers/imports.py @@ -149,6 +149,10 @@ MSGS = { 'misplaced-future', 'Python 2.5 and greater require __future__ import to be the \ first non docstring statement in the module.'), + 'W0407': ('Missing submodule: %s', + 'missing-submodule', + 'Used when trying to import a submodule from a package ' + 'and the submodule is missing.'), } class ImportsChecker(BaseChecker): diff --git a/checkers/variables.py b/checkers/variables.py index 90b7fe7..a0bf796 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -15,13 +15,15 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """variables checkers for Python code """ - +import os import sys from copy import copy import astroid from astroid import are_exclusive, builtin_lookup, AstroidBuildingException +from logilab.common.modutils import load_module_from_name + from pylint.interfaces import IAstroidChecker from pylint.checkers import BaseChecker from pylint.checkers.utils import (PYMETHODS, is_ancestor_name, is_builtin, @@ -192,7 +194,8 @@ builtins. Remember that you should avoid to define new builtins when possible.' # do not print Redefining builtin for additional builtins self.add_message('W0622', args=name, node=stmts[0]) - @check_messages('W0611', 'W0614', 'W0622', 'E0603', 'E0604') + @check_messages('W0611', 'W0614', 'W0622', 'E0603', 'E0604', + 'missing-submodule') def leave_module(self, node): """leave module: check globals """ @@ -217,7 +220,23 @@ builtins. Remember that you should avoid to define new builtins when possible.' del not_consumed[elt_name] continue if elt_name not in node.locals: - self.add_message('E0603', args=elt_name, node=elt) + if not node.package: + self.add_message('E0603', args=elt_name, node=elt) + else: + basename = os.path.splitext(node.file)[0] + if os.path.basename(basename) == '__init__': + name = node.name + "." + elt_name + try: + load_module_from_name(name) + except ImportError: + self.add_message('missing-submodule', + args=elt_name, + node=elt) + except SyntaxError as exc: + # don't yield an syntax-error warning, + # because it will be later yielded + # when the file will be checked + pass # don't check unused imports in __init__ files if not self.config.init_import and node.package: return |