diff options
author | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2011-09-07 09:40:21 +0200 |
---|---|---|
committer | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2011-09-07 09:40:21 +0200 |
commit | 367866786e76c4bdfa71a362a835b1cdec0296aa (patch) | |
tree | 256a29df0a579e33d90a48633e30168bec0e369c | |
parent | 91bc9adc5aed93dc1291a12847627c4d50597b58 (diff) | |
download | pylint-git-367866786e76c4bdfa71a362a835b1cdec0296aa.tar.gz |
closes #74087: handle case where inference of a module return YES
This avoid some cases of "TypeError: '_Yes' object does not support indexing"
when conditionally assigning a nonexisting module to intermediate modules in
a dotted name.
This is only a cosmetic fix to avoid the crash, the actual fix probably
needs a lot of work on the inference module to support conditional
assignment and inspection of several places of assignment, rather than just
the latest one. Probably not worth it, either.
patch by Google
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | checkers/variables.py | 4 | ||||
-rw-r--r-- | test/regrtest_data/import_assign.py | 5 | ||||
-rw-r--r-- | test/test_regr.py | 3 |
4 files changed, 17 insertions, 3 deletions
@@ -1,8 +1,12 @@ ChangeLog for PyLint ==================== -- - * #74742: make allowed name for first argument of class method - configurable (patch by Google) + * #74742: make allowed name for first argument of class method configurable + (patch by Google) + + * #74087: handle case where inference of a module return YES; this avoid + some cases of "TypeError: '_Yes' object does not support indexing" (patch + by Google) 2011-07-18 -- 0.24.0 diff --git a/checkers/variables.py b/checkers/variables.py index 0057ea6f1..f8748ba10 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -1,4 +1,4 @@ -# Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE). +# Copyright (c) 2003-2011 LOGILAB S.A. (Paris, FRANCE). # http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This program is free software; you can redistribute it and/or modify it under @@ -483,6 +483,8 @@ builtins. Remember that you should avoid to define new builtins when possible.' break try: module = module.getattr(name)[0].infer().next() + if module is astng.YES: + return None except astng.NotFoundError: self.add_message('E0611', args=(name, module.name), node=node) return None diff --git a/test/regrtest_data/import_assign.py b/test/regrtest_data/import_assign.py new file mode 100644 index 000000000..c01cd52f7 --- /dev/null +++ b/test/regrtest_data/import_assign.py @@ -0,0 +1,5 @@ +import shmixml.dom.minidom +import xml.dom.minidom + +if 'dom' not in xml.__dict__: + xml.dom = shmixml.dom diff --git a/test/test_regr.py b/test/test_regr.py index c5f01fc9e..1cef0ce82 100644 --- a/test/test_regr.py +++ b/test/test_regr.py @@ -120,6 +120,9 @@ class NonRegrTC(TestCase): got = linter.reporter.finalize().strip() self.failUnlessEqual(got, '') + def test_import_assign_crash(self): + linter.check(join(REGR_DATA, 'import_assign.py')) + def test_module_global_crash(self): linter.check(join(REGR_DATA, 'module_global.py')) got = linter.reporter.finalize().strip() |