diff options
| author | Florent Xicluna <florent.xicluna@gmail.com> | 2013-02-08 01:59:13 +0100 |
|---|---|---|
| committer | Florent Xicluna <florent.xicluna@gmail.com> | 2013-02-08 01:59:13 +0100 |
| commit | 8b2d56f74d94587760c8208e040c0ff6b2791bc6 (patch) | |
| tree | 6add73929c0e3966475350df7876440b0135536b /pyflakes/test/test_other.py | |
| parent | 09d4700a7ce73cd816b35713b0c29e7f98d79bc1 (diff) | |
| download | pyflakes-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.py | 89 |
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 |
