diff options
author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> | 2010-02-25 14:46:20 +0100 |
---|---|---|
committer | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> | 2010-02-25 14:46:20 +0100 |
commit | a530b1a417888c58ed213e366bd6402fa9070944 (patch) | |
tree | a31ffbc82819517380155475273a40558c24d2b5 /checkers/variables.py | |
parent | f3bd873d6096808081b2408c481b98b71f316dcc (diff) | |
download | pylint-a530b1a417888c58ed213e366bd6402fa9070944.tar.gz |
fix #20991: class scope definitions ignored in a genexpr
When checking for variable existence in a method definition, pylint
simply skips the class scope in the scope consumer chain. This technique
works fine with classic methods but doesn't work when analyzing genexprs
defined at class level : for genexprs, we do want the class scope to
be considered.
Diffstat (limited to 'checkers/variables.py')
-rw-r--r-- | checkers/variables.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/checkers/variables.py b/checkers/variables.py index f17c940..b52581c 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -335,13 +335,17 @@ builtins. Remember that you should avoid to define new builtins when possible.' else: start_index = len(self._to_consume) - 1 # iterates through parent scopes, from the inner to the outer + base_scope_type = self._to_consume[start_index][-1] for i in range(start_index, -1, -1): to_consume, consumed, scope_type = self._to_consume[i] # if the current scope is a class scope but it's not the inner # scope, ignore it. This prevents to access this scope instead of # the globals one in function members when there are some common - # names - if scope_type == 'class' and i != start_index: + # names. The only exception is when the starting scope is a + # genexpr and its direct outer scope is a class + if scope_type == 'class' and i != start_index and not ( + base_scope_type == 'genexpr' and i == start_index-1): + # XXX find a way to handle class scope in a smoother way continue # the name has already been consumed, only check it's not a loop # variable used outside the loop |