diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2014-04-30 15:55:46 +0200 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2014-04-30 15:55:46 +0200 |
commit | 1c9a81913bf29977489eb132e9f0103f6b07f62c (patch) | |
tree | 4a420c676cc3447782070df09f0d8add201f32aa | |
parent | b9ce8420907cafa663bc2cb2ef3a7fbfab2cdc0d (diff) | |
parent | e30852960da85111b5b53ea2878975bd58ceb2f9 (diff) | |
download | pyflakes-1c9a81913bf29977489eb132e9f0103f6b07f62c.tar.gz |
Merge pull request #3 from myint/crash
Avoid crash on "return 2"
-rw-r--r-- | pyflakes/checker.py | 6 | ||||
-rw-r--r-- | pyflakes/test/test_other.py | 4 |
2 files changed, 9 insertions, 1 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py index 8f290f6..7055832 100644 --- a/pyflakes/checker.py +++ b/pyflakes/checker.py @@ -693,7 +693,11 @@ class Checker(object): raise RuntimeError("Got impossible expression context: %r" % (node.ctx,)) def RETURN(self, node): - if node.value and not self.scope.returnValue: + if ( + node.value and + hasattr(self.scope, 'returnValue') and + not self.scope.returnValue + ): self.scope.returnValue = node.value self.handleNode(node.value, node) diff --git a/pyflakes/test/test_other.py b/pyflakes/test/test_other.py index ff8716b..f24a721 100644 --- a/pyflakes/test/test_other.py +++ b/pyflakes/test/test_other.py @@ -938,3 +938,7 @@ class TestUnusedAssignment(TestCase): def bar(): yield from foo() ''', m.UndefinedName) + + def test_returnOnly(self): + """Do not crash on lone "return".""" + self.flakes('return 2') |