From 26814f2a05d25b937da0ec3e9ff089a89db3db8b Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 29 Dec 2025 16:21:49 -0800 Subject: [PATCH 1/2] Avoid treating pass/... as no-op for reachability Fixes #16232 The inclusion of these statements dates back to the original `--warn-unreachable` PR (and doesn't provide justification) I've been advocating for more consistent heuristics for allowable unreachable code across type checkers and I can't come up with a good reason that this should be allowed --- mypy/checker.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mypy/checker.py b/mypy/checker.py index 96e41a5e1786..a65969b97568 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -3181,12 +3181,10 @@ def is_noop_for_reachability(self, s: Statement) -> bool: return True elif isinstance(s, ReturnStmt) and is_literal_not_implemented(s.expr): return True - elif isinstance(s, (RaiseStmt, PassStmt)): + elif isinstance(s, RaiseStmt): return True elif isinstance(s, ExpressionStmt): - if isinstance(s.expr, EllipsisExpr): - return True - elif isinstance(s.expr, CallExpr): + if isinstance(s.expr, CallExpr): with self.expr_checker.msg.filter_errors(filter_revealed_type=True): typ = get_proper_type( self.expr_checker.accept( From 773289b52df46375237d24cfd974e5ddfd011840 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Thu, 8 Jan 2026 13:06:34 -0800 Subject: [PATCH 2/2] test --- test-data/unit/check-unreachable-code.test | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test-data/unit/check-unreachable-code.test b/test-data/unit/check-unreachable-code.test index 98c676dbf42b..e4d67055fa00 100644 --- a/test-data/unit/check-unreachable-code.test +++ b/test-data/unit/check-unreachable-code.test @@ -1637,7 +1637,17 @@ class C: return C() else: return NotImplemented +[builtins fixtures/isinstance.pyi] + +[case testPassAndEllipsisUnreachable] +# flags: --warn-unreachable +def f() -> None: + return + pass # E: Statement is unreachable +def g() -> None: + return + ... # E: Statement is unreachable [builtins fixtures/isinstance.pyi] [case testUnreachableStatementPrettyHighlighting]