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
1=== modified file 'NEWS.txt'
2--- NEWS.txt 2013-02-08 00:59:13 +0000
3+++ NEWS.txt 2013-03-06 22:41:21 +0000
4@@ -1,7 +1,16 @@
5-0.6.x (unreleased):
6- - Do not report redefinition of variable for generator expressions and
7- set or dict comprehensions.
8-
9+<<<<<<< TREE
10+0.6.x (unreleased):
11+ - Do not report redefinition of variable for generator expressions and
12+ set or dict comprehensions.
13+
14+=======
15+0.6.x (unreleased):
16+ - Do not report redefinition of variable for a variable used in a list
17+ comprehension in a conditional.
18+ - Do not report redefinition of variable for generator expressions and
19+ set or dict comprehensions.
20+
21+>>>>>>> MERGE-SOURCE
22 0.6.1 (2013-01-29):
23 - Fix detection of variables in augmented assignments.
24
25
26=== modified file 'pyflakes/checker.py'
27--- pyflakes/checker.py 2013-02-21 16:40:37 +0000
28+++ pyflakes/checker.py 2013-03-06 22:41:21 +0000
29@@ -368,7 +368,8 @@
30 existing = self.scope.get(value.name)
31 if not redefinedWhileUnused and self.hasParent(value.source, ast.ListComp):
32 if (existing and reportRedef
33- and not self.hasParent(existing.source, (ast.For, ast.ListComp))):
34+ and not self.hasParent(existing.source, (ast.For, ast.ListComp))
35+ and not self.differentForks(node, existing.source)):
36 self.report(messages.RedefinedInListComp,
37 node.lineno, value.name, existing.source.lineno)
38
39
40=== modified file 'pyflakes/test/test_other.py'
41--- pyflakes/test/test_other.py 2013-02-08 00:59:13 +0000
42+++ pyflakes/test/test_other.py 2013-03-06 22:41:21 +0000
43@@ -213,6 +213,31 @@
44 pass
45 ''', m.RedefinedWhileUnused)
46
47+ def test_redefinedIfElseInListComp(self):
48+ """
49+ Test that shadowing a variable in a list comprehension in
50+ an if and else block does not raise a warning.
51+ """
52+ self.flakes('''
53+ if False:
54+ a = 1
55+ else:
56+ [a for a in '12']
57+ ''')
58+
59+ def test_redefinedElseInListComp(self):
60+ """
61+ Test that shadowing a variable in a list comprehension in
62+ an else (or if) block raises a warning.
63+ """
64+ self.flakes('''
65+ if False:
66+ pass
67+ else:
68+ a = 1
69+ [a for a in '12']
70+ ''', m.RedefinedInListComp)
71+
72 def test_functionDecorator(self):
73 """
74 Test that shadowing a function definition with a decorated version of

Subscribers

People subscribed via source and target branches

to all changes: