summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Vandenberg <jayvdb@gmail.com>2018-07-16 10:25:37 +0700
committerJohn Vandenberg <jayvdb@gmail.com>2018-10-31 15:57:43 +0700
commit2bc5a2d8d2a709980dd78e484d965b8f7eaeb146 (patch)
tree9a47aefd4855089536fbe2389ca08c34fa9eed46
parent47a164136982ea6ef80f302200b2a29d3a4b1c3c (diff)
downloadpyflakes-2bc5a2d8d2a709980dd78e484d965b8f7eaeb146.tar.gz
Simplify Python 3 except scope
The existing variable with the same name given to the exception can only be in the same scope.
-rw-r--r--pyflakes/checker.py15
1 files changed, 4 insertions, 11 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 3dd968d..f520325 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -1461,15 +1461,9 @@ class Checker(object):
# to more accurately determine if the name is used in the except:
# block.
- for scope in self.scopeStack[::-1]:
- try:
- binding = scope.pop(node.name)
- except KeyError:
- pass
- else:
- prev_definition = scope, binding
- break
- else:
+ try:
+ prev_definition = self.scope.pop(node.name)
+ except KeyError:
prev_definition = None
self.handleNodeStore(node)
@@ -1494,8 +1488,7 @@ class Checker(object):
# Restore.
if prev_definition:
- scope, binding = prev_definition
- scope[node.name] = binding
+ self.scope[node.name] = prev_definition
def ANNASSIGN(self, node):
if node.value: