summaryrefslogtreecommitdiff
path: root/pyflakes/test/test_other.py
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2013-02-08 01:59:13 +0100
committerFlorent Xicluna <florent.xicluna@gmail.com>2013-02-08 01:59:13 +0100
commit8b2d56f74d94587760c8208e040c0ff6b2791bc6 (patch)
tree6add73929c0e3966475350df7876440b0135536b /pyflakes/test/test_other.py
parent09d4700a7ce73cd816b35713b0c29e7f98d79bc1 (diff)
downloadpyflakes-8b2d56f74d94587760c8208e040c0ff6b2791bc6.tar.gz
Do not report redefinition of variable for generator expression and set / dict comprehensions.
Diffstat (limited to 'pyflakes/test/test_other.py')
-rw-r--r--pyflakes/test/test_other.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/pyflakes/test/test_other.py b/pyflakes/test/test_other.py
index c3b8507..7fcfd55 100644
--- a/pyflakes/test/test_other.py
+++ b/pyflakes/test/test_other.py
@@ -55,6 +55,95 @@ class Test(harness.Test):
[1 for a, b in [(1, 2)]]
''')
+ def test_redefinedInGenerator(self):
+ """
+ Test that reusing a variable in a generator does not raise
+ a warning.
+ """
+ self.flakes('''
+ a = 1
+ (1 for a, b in [(1, 2)])
+ ''')
+ self.flakes('''
+ class A:
+ a = 1
+ list(1 for a, b in [(1, 2)])
+ ''')
+ self.flakes('''
+ def f():
+ a = 1
+ (1 for a, b in [(1, 2)])
+ ''', m.UnusedVariable)
+ self.flakes('''
+ (1 for a, b in [(1, 2)])
+ (1 for a, b in [(1, 2)])
+ ''')
+ self.flakes('''
+ for a, b in [(1, 2)]:
+ pass
+ (1 for a, b in [(1, 2)])
+ ''')
+
+ @skipIf(version_info < (2, 7), "Python >= 2.7 only")
+ def test_redefinedInSetComprehension(self):
+ """
+ Test that reusing a variable in a set comprehension does not raise
+ a warning.
+ """
+ self.flakes('''
+ a = 1
+ {1 for a, b in [(1, 2)]}
+ ''')
+ self.flakes('''
+ class A:
+ a = 1
+ {1 for a, b in [(1, 2)]}
+ ''')
+ self.flakes('''
+ def f():
+ a = 1
+ {1 for a, b in [(1, 2)]}
+ ''', m.UnusedVariable)
+ self.flakes('''
+ {1 for a, b in [(1, 2)]}
+ {1 for a, b in [(1, 2)]}
+ ''')
+ self.flakes('''
+ for a, b in [(1, 2)]:
+ pass
+ {1 for a, b in [(1, 2)]}
+ ''')
+
+ @skipIf(version_info < (2, 7), "Python >= 2.7 only")
+ def test_redefinedInDictComprehension(self):
+ """
+ Test that reusing a variable in a dict comprehension does not raise
+ a warning.
+ """
+ self.flakes('''
+ a = 1
+ {1: 42 for a, b in [(1, 2)]}
+ ''')
+ self.flakes('''
+ class A:
+ a = 1
+ {1: 42 for a, b in [(1, 2)]}
+ ''')
+ self.flakes('''
+ def f():
+ a = 1
+ {1: 42 for a, b in [(1, 2)]}
+ ''', m.UnusedVariable)
+ self.flakes('''
+ {1: 42 for a, b in [(1, 2)]}
+ {1: 42 for a, b in [(1, 2)]}
+ ''')
+ self.flakes('''
+ for a, b in [(1, 2)]:
+ pass
+ {1: 42 for a, b in [(1, 2)]}
+ ''')
+
def test_redefinedFunction(self):
"""
Test that shadowing a function definition with another one raises a