summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-05-17 18:44:23 +0300
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-05-17 18:44:23 +0300
commit3da15c9534ea143d30e61d26b437c7bedd615148 (patch)
treed8b40b96e086f8de6b450046aed05a4261468b06
parent17cd1d604acf75913ab30d2caccb017242de0495 (diff)
downloadpylint-3da15c9534ea143d30e61d26b437c7bedd615148.tar.gz
Don't emit no-name-in-module for nodes protected by an except clause which handles ImportError, Exception or bare except.
-rw-r--r--pylint/checkers/variables.py6
-rw-r--r--pylint/test/functional/no_name_in_module.py12
2 files changed, 14 insertions, 4 deletions
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index 3bde1d1..3efc7c8 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -31,7 +31,7 @@ from pylint.checkers.utils import (
PYMETHODS, is_ancestor_name, is_builtin,
is_defined_before, is_error, is_func_default, is_func_decorator,
assign_parent, check_messages, is_inside_except, clobber_in_except,
- get_all_elements, has_known_bases, excepts_import_error)
+ get_all_elements, has_known_bases, node_ignores_exception)
import six
SPECIAL_OBJ = re.compile("^_{2}[a-z]+_{2}$")
@@ -973,7 +973,7 @@ builtins. Remember that you should avoid to define new builtins when possible.'
@check_messages('no-name-in-module')
def visit_import(self, node):
"""check modules attribute accesses"""
- if excepts_import_error(node.parent):
+ if node_ignores_exception(node, ImportError):
# No need to verify this, since ImportError is already
# handled by the client code.
return
@@ -989,7 +989,7 @@ builtins. Remember that you should avoid to define new builtins when possible.'
@check_messages('no-name-in-module')
def visit_from(self, node):
"""check modules attribute accesses"""
- if excepts_import_error(node.parent):
+ if node_ignores_exception(node, ImportError):
# No need to verify this, since ImportError is already
# handled by the client code.
return
diff --git a/pylint/test/functional/no_name_in_module.py b/pylint/test/functional/no_name_in_module.py
index 8103d47..31c709b 100644
--- a/pylint/test/functional/no_name_in_module.py
+++ b/pylint/test/functional/no_name_in_module.py
@@ -1,4 +1,4 @@
-#pylint: disable=W0401,W0611,no-absolute-import,invalid-name,import-error
+#pylint: disable=W0401,W0611,no-absolute-import,invalid-name,import-error,bare-except,broad-except
"""check unexistant names imported are reported"""
from __future__ import print_function
@@ -44,3 +44,13 @@ try:
import collections.indeed_missing # [no-name-in-module]
except ValueError:
pass
+
+try:
+ import collections.dont_emit
+except Exception:
+ pass
+
+try:
+ import collections.please_dont_emit
+except:
+ pass