PY-83597 False positive type narrowing in expressions with "and"

GitOrigin-RevId: e39cae3490ef0f0f151842f428a45d14d2c4d9ed
This commit is contained in:
Aleksandr.Govenko
2025-09-30 10:30:37 +00:00
committed by intellij-monorepo-bot
parent acba8a231a
commit 663b57857e
19 changed files with 339 additions and 272 deletions
@@ -151,6 +151,32 @@ public class Py3TypeTest extends PyTestCase {
expr = d.pop("abc", None)""");
}
// PY-83351
public void testWhileStatementNarrowing() {
doTest("int",
"""
def foo(x: int | None):
while x:
expr = x
x = None
""");
doTest("int",
"""
def foo(x: int | None):
while not (not (((not (not x))))):
expr = x
x = None
""");
}
// PY-83597
public void testAndExpressionNarrowing() {
doTest("int", """
def foo(x: int | None):
x and (expr := x)
""");
}
// PY-83348
public void testOrExpressionType() {
doTest("int | str", """