diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2014-03-30 04:53:30 +0200 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2014-03-30 04:53:30 +0200 |
commit | 20c7c950a79f24ad53cfc874689e32b903493f36 (patch) | |
tree | 527d7116f1e084f9bc7472eac12d147964625c61 | |
parent | a55a126350880ef378cb7e8d6576e400d7f6205d (diff) | |
download | pyflakes-20c7c950a79f24ad53cfc874689e32b903493f36.tar.gz |
Do not bind the function in the current scope, until its arguments are handled; fixes lp:1270952
-rw-r--r-- | NEWS.txt | 2 | ||||
-rw-r--r-- | pyflakes/checker.py | 2 | ||||
-rw-r--r-- | pyflakes/test/test_imports.py | 12 |
3 files changed, 15 insertions, 1 deletions
@@ -6,6 +6,8 @@ UNRELEASED: loop variable. - Report undefined name for `(a, b) = (1, 2)` but not for the general unpacking `(a, b) = func()`. + - Correctly detect when an imported module is used in default arguments + of a method, when the method and the module use the same name. 0.8.0 (2014-03-22): - Adapt for the AST in Python 3.4. diff --git a/pyflakes/checker.py b/pyflakes/checker.py index f58bc70..cb12906 100644 --- a/pyflakes/checker.py +++ b/pyflakes/checker.py @@ -712,8 +712,8 @@ class Checker(object): def FUNCTIONDEF(self, node): for deco in node.decorator_list: self.handleNode(deco, node) - self.addBinding(node, FunctionDefinition(node.name, node)) self.LAMBDA(node) + self.addBinding(node, FunctionDefinition(node.name, node)) if self.withDoctest: self.deferFunction(lambda: self.handleDoctests(node)) diff --git a/pyflakes/test/test_imports.py b/pyflakes/test/test_imports.py index 164f182..8895856 100644 --- a/pyflakes/test/test_imports.py +++ b/pyflakes/test/test_imports.py @@ -671,6 +671,18 @@ class Test(TestCase): self.i ''') + def test_importUsedInMethodDefinition(self): + """ + Method named 'foo' with default args referring to module named 'foo'. + """ + self.flakes(''' + import foo + + class Thing(object): + def foo(self, parser=foo.parse_foo): + pass + ''') + def test_futureImport(self): """__future__ is special.""" self.flakes('from __future__ import division') |