Merge lp:~pyflakes-dev/pyflakes/1112067-comprehension-scope into lp:pyflakes

Proposed by Florent
Status: Merged
Merged at revision: 72
Proposed branch: lp:~pyflakes-dev/pyflakes/1112067-comprehension-scope
Merge into: lp:pyflakes
Diff against target: 74 lines (+40/-5) (has conflicts)
3 files modified
NEWS.txt (+13/-4)
pyflakes/checker.py (+2/-1)
pyflakes/test/test_other.py (+25/-0)
Text conflict in NEWS.txt
To merge this branch: bzr merge lp:~pyflakes-dev/pyflakes/1112067-comprehension-scope
Reviewer Review Type Date Requested Status
Pyflakes Dev Pending
Review via email: mp+147264@code.launchpad.net

Description of the change

Fixes the case for generator expressions / dict comprehensions / set comprehensions

To post a comment you must log in.
69. By Florent

Do not report redefinition of variable for a variable used in a list comprehension in a conditional

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS.txt'
--- NEWS.txt 2013-02-08 00:59:13 +0000
+++ NEWS.txt 2013-03-06 22:41:21 +0000
@@ -1,7 +1,16 @@
10.6.x (unreleased):1<<<<<<< TREE
2 - Do not report redefinition of variable for generator expressions and20.6.x (unreleased):
3 set or dict comprehensions.3 - Do not report redefinition of variable for generator expressions and
44 set or dict comprehensions.
5
6=======
70.6.x (unreleased):
8 - Do not report redefinition of variable for a variable used in a list
9 comprehension in a conditional.
10 - Do not report redefinition of variable for generator expressions and
11 set or dict comprehensions.
12
13>>>>>>> MERGE-SOURCE
50.6.1 (2013-01-29):140.6.1 (2013-01-29):
6 - Fix detection of variables in augmented assignments.15 - Fix detection of variables in augmented assignments.
716
817
=== modified file 'pyflakes/checker.py'
--- pyflakes/checker.py 2013-02-21 16:40:37 +0000
+++ pyflakes/checker.py 2013-03-06 22:41:21 +0000
@@ -368,7 +368,8 @@
368 existing = self.scope.get(value.name)368 existing = self.scope.get(value.name)
369 if not redefinedWhileUnused and self.hasParent(value.source, ast.ListComp):369 if not redefinedWhileUnused and self.hasParent(value.source, ast.ListComp):
370 if (existing and reportRedef370 if (existing and reportRedef
371 and not self.hasParent(existing.source, (ast.For, ast.ListComp))):371 and not self.hasParent(existing.source, (ast.For, ast.ListComp))
372 and not self.differentForks(node, existing.source)):
372 self.report(messages.RedefinedInListComp,373 self.report(messages.RedefinedInListComp,
373 node.lineno, value.name, existing.source.lineno)374 node.lineno, value.name, existing.source.lineno)
374375
375376
=== modified file 'pyflakes/test/test_other.py'
--- pyflakes/test/test_other.py 2013-02-08 00:59:13 +0000
+++ pyflakes/test/test_other.py 2013-03-06 22:41:21 +0000
@@ -213,6 +213,31 @@
213 pass213 pass
214 ''', m.RedefinedWhileUnused)214 ''', m.RedefinedWhileUnused)
215215
216 def test_redefinedIfElseInListComp(self):
217 """
218 Test that shadowing a variable in a list comprehension in
219 an if and else block does not raise a warning.
220 """
221 self.flakes('''
222 if False:
223 a = 1
224 else:
225 [a for a in '12']
226 ''')
227
228 def test_redefinedElseInListComp(self):
229 """
230 Test that shadowing a variable in a list comprehension in
231 an else (or if) block raises a warning.
232 """
233 self.flakes('''
234 if False:
235 pass
236 else:
237 a = 1
238 [a for a in '12']
239 ''', m.RedefinedInListComp)
240
216 def test_functionDecorator(self):241 def test_functionDecorator(self):
217 """242 """
218 Test that shadowing a function definition with a decorated version of243 Test that shadowing a function definition with a decorated version of

Subscribers

People subscribed via source and target branches

to all changes: