summaryrefslogtreecommitdiff
path: root/checkers/variables.py
diff options
context:
space:
mode:
authorTorsten Marek <tmarek@google.com>2013-01-08 19:26:13 +0100
committerTorsten Marek <tmarek@google.com>2013-01-08 19:26:13 +0100
commit406263c27ebf898184fed6696feeae450b963adb (patch)
tree0af24fd57a51e89cbf1e51949c70f3163b1c27df /checkers/variables.py
parente5837c47144284bb5465add6147fe6860c602f83 (diff)
downloadpylint-git-406263c27ebf898184fed6696feeae450b963adb.tar.gz
Fixed a couple of bugs in the __all__ handling and added a new
warning about non-string objects in __all__. Closes #112698 --HG-- branch : stable
Diffstat (limited to 'checkers/variables.py')
-rw-r--r--checkers/variables.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/checkers/variables.py b/checkers/variables.py
index 01ea6f81b..d094e6c7e 100644
--- a/checkers/variables.py
+++ b/checkers/variables.py
@@ -172,14 +172,22 @@ builtins. Remember that you should avoid to define new builtins when possible.'
# attempt to check for __all__ if defined
if '__all__' in node.locals:
assigned = node.igetattr('__all__').next()
- for elt in getattr(assigned, 'elts', ()):
- elt_name = elt.value
- # If elt is in not_consumed, remove it from not_consumed
- if elt_name in not_consumed:
- del not_consumed[elt_name]
- continue
- if elt_name not in node.locals:
- self.add_message('E0603', args=elt_name, node=elt)
+ if assigned is not astng.YES:
+ for elt in getattr(assigned, 'elts', ()):
+ try:
+ elt_name = elt.infer().next()
+ except astng.InferenceError:
+ continue
+
+ if not isinstance(elt_name, astng.Const):
+ continue
+ elt_name = elt.value
+ # If elt is in not_consumed, remove it from not_consumed
+ if elt_name in not_consumed:
+ del not_consumed[elt_name]
+ continue
+ if elt_name not in node.locals:
+ self.add_message('E0603', args=elt_name, node=elt)
# don't check unused imports in __init__ files
if not self.config.init_import and node.package:
return