From 647d413831769bc201139b7bbea093ad8b9ad8bc Mon Sep 17 00:00:00 2001 From: Niklas Mertsch Date: Thu, 29 Aug 2024 17:52:56 +0200 Subject: [PATCH] Add test cases for #14209 --- test-data/unit/check-possibly-undefined.test | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test-data/unit/check-possibly-undefined.test b/test-data/unit/check-possibly-undefined.test index ae277949c0494..a88fec1cccd14 100644 --- a/test-data/unit/check-possibly-undefined.test +++ b/test-data/unit/check-possibly-undefined.test @@ -1043,3 +1043,40 @@ def foo(x: Union[int, str]) -> None: assert_never(x) f # OK [builtins fixtures/tuple.pyi] + +[case testForLoopBreakElseDefinition] +# flags: --enable-error-code possibly-undefined +# Regression test for https://github.com/python/mypy/issues/14209 +for i in [1, 2, 3]: + if i: + b = i + break +else: + b = 1 + +b # OK + +[case testForLoopBreakElseException] +# flags: --enable-error-code possibly-undefined +# Regression test for https://github.com/python/mypy/issues/14209 +for i in [1, 2, 3]: + if i: + b = i + break +else: + raise BaseException() + +b # OK +[builtins fixtures/exception.pyi] + +[case testForLoopBreakElseEmpty] +# flags: --enable-error-code possibly-undefined +# Regression test for https://github.com/python/mypy/issues/14209 +for i in [1, 2, 3]: + b = i + if i: + break +else: + b = 1 + +b # OK