From 2f678fd9c90698e110a931cd11255de72ea2e55a Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sat, 7 Mar 2026 19:33:48 +0000 Subject: [PATCH] `directives_type_checking.py`: do not assert that type checkers must ignore all type errors in `if not TYPE_CHECKING` blocks --- conformance/results/results.html | 2 +- .../results/ty/directives_type_checking.toml | 8 +------- conformance/tests/directives_type_checking.py | 14 +++++++------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/conformance/results/results.html b/conformance/results/results.html index 249f6b700..25453296c 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -1176,7 +1176,7 @@

Python Type System Conformance Test Results

Pass Pass Pass -
Partial

Attempts to detect some errors even in blocks it determines to be unreachable, including in `if not TYPE_CHECKING` blocks.

+Pass      directives_type_ignore
Partial

Does not honor "# type: ignore" comment if comment includes additional text.

diff --git a/conformance/results/ty/directives_type_checking.toml b/conformance/results/ty/directives_type_checking.toml index a9ad6809b..cdd4d0cd9 100644 --- a/conformance/results/ty/directives_type_checking.toml +++ b/conformance/results/ty/directives_type_checking.toml @@ -1,11 +1,5 @@ -conformance_automated = "Fail" -conformant = "Partial" -notes = """ -Attempts to detect some errors even in blocks it determines to be unreachable, including in `if not TYPE_CHECKING` blocks. -""" +conformance_automated = "Pass" errors_diff = """ -Line 11: Unexpected errors ['directives_type_checking.py:11:14: error[invalid-assignment] Object of type `Literal[""]` is not assignable to `int`'] """ output = """ -directives_type_checking.py:11:14: error[invalid-assignment] Object of type `Literal[""]` is not assignable to `int` """ diff --git a/conformance/tests/directives_type_checking.py b/conformance/tests/directives_type_checking.py index 55a2d52df..f491560e5 100644 --- a/conformance/tests/directives_type_checking.py +++ b/conformance/tests/directives_type_checking.py @@ -7,12 +7,12 @@ from typing import TYPE_CHECKING, assert_type -if not TYPE_CHECKING: - a: int = "" # This should not generate an error +def foo(x: list[int], y: list[str]) -> None: + z: list[int] | list[str] -if TYPE_CHECKING: - b: list[int] = [1, 2, 3] -else: - b: list[str] = ["a", "b", "c"] + if TYPE_CHECKING: + z = x + else: + z = y -assert_type(b, list[int]) + assert_type(z, list[int])