From b6a4c1d7b9db6dee06bd6b9582498a4b8732fd0c Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 7 Apr 2016 16:44:21 -0700 Subject: [PATCH] Skip unreachable blocks in ThirdPass. Fixes #1319. --- mypy/semanal.py | 5 +++++ mypy/test/data/check-unreachable-code.test | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/mypy/semanal.py b/mypy/semanal.py index 58e47f14ed94..563e9a580d2b 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -2388,6 +2388,11 @@ def visit_file(self, file_node: MypyFile, fnam: str) -> None: file_node.accept(self) self.errors.set_ignored_lines(set()) + def visit_block(self, b: Block) -> None: + if b.is_unreachable: + return + super().visit_block(b) + def visit_func_def(self, fdef: FuncDef) -> None: self.errors.push_function(fdef.name()) self.analyze(fdef.type) diff --git a/mypy/test/data/check-unreachable-code.test b/mypy/test/data/check-unreachable-code.test index 8aa0fa6eef38..00a67991fbdb 100644 --- a/mypy/test/data/check-unreachable-code.test +++ b/mypy/test/data/check-unreachable-code.test @@ -89,3 +89,12 @@ if MYPY: else: None + '' [builtins fixtures/bool.py] + +[case testConditionalClassDefPY3] +def f(): pass +PY3 = f() +if PY3: + pass +else: + class X(object): + pass