diff options
author | tmarek <tmarek@google.com> | 2013-01-08 19:26:13 +0100 |
---|---|---|
committer | tmarek <tmarek@google.com> | 2013-01-08 19:26:13 +0100 |
commit | d9cf9d13e239a2b19b1dc485863705f0b8d328ae (patch) | |
tree | 2536cc525f6e9df79c9aecb1e99ec80e773056dc | |
parent | 7e2cbf9efb14df4e4a5178522bb5c9476b892a1c (diff) | |
download | pylint-stable.tar.gz |
Fixed a couple of bugs in the __all__ handling and added a newstable
warning about non-string objects in __all__.
Closes #112698
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | checkers/variables.py | 24 | ||||
-rw-r--r-- | test/input/func_all_undefined.py | 8 | ||||
-rw-r--r-- | test/input/func_noerror_all_no_inference.py | 14 | ||||
-rw-r--r-- | test/messages/func_all_undefined.txt | 1 |
5 files changed, 45 insertions, 11 deletions
@@ -6,7 +6,7 @@ ChangeLog for PyLint (patch by Martin Pool) * #110853: fix a crash when an __init__ method in a base class has been - created by assignment rather than direct function definition. (patch by + created by assignment rather than direct function definition (patch by Torsten Marek) * #110838: fix pylint-gui crash when include-ids is activated (patch by @@ -14,8 +14,11 @@ ChangeLog for PyLint * #110839: bind <F5> to Run button in pylint-gui - * #112667: Fix emission of reimport warnings for mixed imports and extend - the testcase. (patch by Torsten Marek) + * #112667: fix emission of reimport warnings for mixed imports and extend + the testcase (patch by Torsten Marek) + + * #112698: fixed crashes related to non-inferable __all__ attributes and + invalid __all__ contents (patch by Torsten Marek) 2012-10-05 -- 0.26.0 diff --git a/checkers/variables.py b/checkers/variables.py index 01ea6f8..d094e6c 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 diff --git a/test/input/func_all_undefined.py b/test/input/func_all_undefined.py new file mode 100644 index 0000000..4dd167c --- /dev/null +++ b/test/input/func_all_undefined.py @@ -0,0 +1,8 @@ +"""Test that non-inferable __all__ variables do not make PyLint crash. + +""" +# pylint: disable=R0903,R0201,W0612 + +__revision__ = 0 + +__all__ = [SomeUndefinedName] diff --git a/test/input/func_noerror_all_no_inference.py b/test/input/func_noerror_all_no_inference.py new file mode 100644 index 0000000..2d2062d --- /dev/null +++ b/test/input/func_noerror_all_no_inference.py @@ -0,0 +1,14 @@ +"""Test that non-inferable __all__ variables do not make PyLint crash. + +""" +# pylint: disable=R0903,R0201,W0612 + +__revision__ = 0 + +__all__ = sorted([ + 'Dummy', + 'NonExistant', + 'path', + 'func', + 'inner', + 'InnerKlass']) diff --git a/test/messages/func_all_undefined.txt b/test/messages/func_all_undefined.txt new file mode 100644 index 0000000..f4170f2 --- /dev/null +++ b/test/messages/func_all_undefined.txt @@ -0,0 +1 @@ +E: 8: Undefined variable 'SomeUndefinedName' |