diff options
author | Steven Myint <git@stevenmyint.com> | 2014-04-26 08:40:18 -0700 |
---|---|---|
committer | Steven Myint <git@stevenmyint.com> | 2014-04-26 08:40:18 -0700 |
commit | e30852960da85111b5b53ea2878975bd58ceb2f9 (patch) | |
tree | 022646882d446f7b4d25c661d0da52d8c0fdd881 | |
parent | b8af00d395281045135f4decbafe796b12f3b2e2 (diff) | |
download | pyflakes-e30852960da85111b5b53ea2878975bd58ceb2f9.tar.gz |
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') |