From 8dd5cc5b3efabf50f5f43deb3d4521b7d0b37e6d Mon Sep 17 00:00:00 2001 From: David Peter Date: Thu, 19 Dec 2024 12:41:58 +0100 Subject: [PATCH] Add cross-module test to show that result is based on type inference --- .../mdtest/statically_known_branches.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/red_knot_python_semantic/resources/mdtest/statically_known_branches.md b/crates/red_knot_python_semantic/resources/mdtest/statically_known_branches.md index 1a588d220d..ea3c1f50d1 100644 --- a/crates/red_knot_python_semantic/resources/mdtest/statically_known_branches.md +++ b/crates/red_knot_python_semantic/resources/mdtest/statically_known_branches.md @@ -160,6 +160,34 @@ both_checks_true other ``` +## Based on type inference + +For the the rest of this test suite, we will mostly use `True` and `False` literals to indicate +statically known conditions, but here, we show that the results are truly based on type inference, +not some special handling of specific conditions in semantic index building. We use two modules to +demonstrate this, since semantic index building is inherently single-module: + +```py path=module.py +class AlwaysTrue: + def __bool__(self) -> Literal[True]: + return True +``` + +```py +from module import AlwaysTrue + +if AlwaysTrue(): + yes = True +else: + no = True + +# no error +yes + +# error: [unresolved-reference] +no +``` + ## If statements The rest of this document contains tests for various control flow elements. This section tests `if`