From a378ff38dcce0b98b463c25d63dcbe49a49ba7e6 Mon Sep 17 00:00:00 2001 From: David Peter Date: Thu, 28 Nov 2024 14:29:35 +0100 Subject: [PATCH] [red-knot] Fix Boolean flags in mdtests (#14654) ## Summary Similar to #14652, but now with conditions that are `Literal[True]` (instead of `Literal[False]`), where we want them to be `bool`. --- .../resources/mdtest/subscript/class.md | 15 +++++++++------ .../resources/mdtest/subscript/instance.md | 5 +++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/red_knot_python_semantic/resources/mdtest/subscript/class.md b/crates/red_knot_python_semantic/resources/mdtest/subscript/class.md index 56870fefc61ca..ee26274ae027c 100644 --- a/crates/red_knot_python_semantic/resources/mdtest/subscript/class.md +++ b/crates/red_knot_python_semantic/resources/mdtest/subscript/class.md @@ -21,10 +21,11 @@ reveal_type(Identity[0]) # revealed: str ## Class getitem union ```py -flag = True +def bool_instance() -> bool: + return True class UnionClassGetItem: - if flag: + if bool_instance(): def __class_getitem__(cls, item: int) -> str: return item @@ -59,9 +60,10 @@ reveal_type(x[0]) # revealed: str | int ## Class getitem with unbound method union ```py -flag = True +def bool_instance() -> bool: + return True -if flag: +if bool_instance(): class Spam: def __class_getitem__(self, x: int) -> str: return "foo" @@ -77,9 +79,10 @@ reveal_type(Spam[42]) ## TODO: Class getitem non-class union ```py -flag = True +def bool_instance() -> bool: + return True -if flag: +if bool_instance(): class Eggs: def __class_getitem__(self, x: int) -> str: return "foo" diff --git a/crates/red_knot_python_semantic/resources/mdtest/subscript/instance.md b/crates/red_knot_python_semantic/resources/mdtest/subscript/instance.md index a7d170a29b490..b9d17ffb002f1 100644 --- a/crates/red_knot_python_semantic/resources/mdtest/subscript/instance.md +++ b/crates/red_knot_python_semantic/resources/mdtest/subscript/instance.md @@ -30,10 +30,11 @@ reveal_type(Identity()[0]) # revealed: int ## Getitem union ```py -flag = True +def bool_instance() -> bool: + return True class Identity: - if flag: + if bool_instance(): def __getitem__(self, index: int) -> int: return index