Skip to content

Commit

Permalink
Fix bug with exception variable reuse in deferred node.
Browse files Browse the repository at this point in the history
  • Loading branch information
Guido van Rossum committed Oct 20, 2016
1 parent 48fa2ef commit 971c426
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,8 @@ def visit_try_without_finally(self, s: TryStmt, try_frame: bool) -> None:
'accept outside except: blocks even in '
'python 2)'.format(s.vars[i].name))
var = cast(Var, s.vars[i].node)
var.type = DeletedType(source=source)
if not self.current_node_deferred:
var.type = DeletedType(source=source)
self.binder.cleanse(s.vars[i])
if s.else_body:
self.accept(s.else_body)
Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/check-statements.test
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,17 @@ e = 1 # E: Assignment to variable 'e' outside except: block
e = E1() # E: Assignment to variable 'e' outside except: block
[builtins fixtures/exception.pyi]

[case testExceptionVariableReuseInDeferredNode]
def f(*a: BaseException) -> int:
x
try: pass
except BaseException as err: pass
try: pass
except BaseException as err: f(err)
x = f()
[builtins fixtures/exception.pyi]


[case testArbitraryExpressionAsExceptionType]
import typing
a = BaseException
Expand Down

0 comments on commit 971c426

Please sign in to comment.