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 /checkers/variables.py | |
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)
Diffstat (limited to 'checkers/variables.py')
-rw-r--r-- | checkers/variables.py | 11 |
1 files changed, 9 insertions, 2 deletions
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] |