From 2d0f83924ebf81c9858d6d8c5fed5ee6b2d34478 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Fri, 21 Apr 2023 14:16:12 -0600 Subject: [PATCH] Regression test for make_simplified_union truthiness Add a test for the code path exercised in #15094 --- test-data/unit/check-errorcodes.test | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test-data/unit/check-errorcodes.test b/test-data/unit/check-errorcodes.test index 88b78e54f211..33c8f7365375 100644 --- a/test-data/unit/check-errorcodes.test +++ b/test-data/unit/check-errorcodes.test @@ -805,6 +805,22 @@ j = [x for x in lst if False] # E: If condition in comprehension is a k = [x for x in lst if isinstance(x, int) or foo()] # E: If condition in comprehension is always true [redundant-expr] [builtins fixtures/isinstancelist.pyi] +[case testRedundantExprTruthiness] +# flags: --enable-error-code redundant-expr +from typing import List + +def maybe() -> bool: ... + +class Foo: + def __init__(self, x: List[int]) -> None: + self.x = x or [] + + def method(self) -> int: + if not self.x or maybe(): + return 1 + return 2 +[builtins fixtures/list.pyi] + [case testNamedTupleNameMismatch] from typing import NamedTuple