diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2011-09-07 10:25:19 +0200 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2011-09-07 10:25:19 +0200 |
commit | 83c27d8b47d034d6eb51977bdd360b2c24b69f91 (patch) | |
tree | a22dd3d4ffa5681e1af6ad61292975a67198a4d5 | |
parent | 9e9fd6cafec51a03c292e6246e802f749b1589b7 (diff) | |
download | pylint-83c27d8b47d034d6eb51977bdd360b2c24b69f91.tar.gz |
closes #74747: don't crash when lookup up a special attribute in class scope
(patch by google)
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | checkers/variables.py | 11 | ||||
-rw-r--r-- | test/regrtest_data/special_attr_scope_lookup_crash.py | 3 | ||||
-rw-r--r-- | test/test_regr.py | 3 |
4 files changed, 18 insertions, 2 deletions
@@ -11,7 +11,10 @@ ChangeLog for PyLint * #74745: make "too general" exception names configurable (patch by Google) + * #74747: crash occurs when lookup up a special attribute in class scope + (patch by google) + 2011-07-18 -- 0.24.0 * #69738: add regular expressions support for "generated-members" diff --git a/checkers/variables.py b/checkers/variables.py index f8748ba..ce98e04 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -331,8 +331,15 @@ builtins. Remember that you should avoid to define new builtins when possible.' return astmts = [stmt for stmt in node.lookup(name)[1] if hasattr(stmt, 'ass_type')] - # filter variables according their respective scope - if not astmts or astmts[0].statement().parent_of(node): + # filter variables according their respective scope test is_statement + # and parent to avoid #74747. This is not a total fix, which would + # introduce a mechanism similar to special attribute lookup in + # modules. Also, in order to get correct inference in this case, the + # scope lookup rules would need to be changed to return the initial + # assignment (which does not exist in code per se) as well as any later + # modifications. + if not astmts or (astmts[0].is_statement or astmts[0].parent) \ + and astmts[0].statement().parent_of(node): _astmts = [] else: _astmts = astmts[:1] diff --git a/test/regrtest_data/special_attr_scope_lookup_crash.py b/test/regrtest_data/special_attr_scope_lookup_crash.py new file mode 100644 index 0000000..b693a9f --- /dev/null +++ b/test/regrtest_data/special_attr_scope_lookup_crash.py @@ -0,0 +1,3 @@ +class Klass(object): + """A""" + __doc__ += "B" diff --git a/test/test_regr.py b/test/test_regr.py index 1cef0ce..e0261ac 100644 --- a/test/test_regr.py +++ b/test/test_regr.py @@ -123,6 +123,9 @@ class NonRegrTC(TestCase): def test_import_assign_crash(self): linter.check(join(REGR_DATA, 'import_assign.py')) + def test_special_attr_scope_lookup_crash(self): + linter.check(join(REGR_DATA, 'special_attr_scope_lookup_crash.py')) + def test_module_global_crash(self): linter.check(join(REGR_DATA, 'module_global.py')) got = linter.reporter.finalize().strip() |