From 710aa1394c579567057cd89a09ee375fbb8bcd3f Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Sun, 1 Feb 2026 03:00:08 -0600 Subject: [PATCH 1/2] add test for 19918: our example code --- test-data/unit/check-redefine.test | 8 ++++++++ test-data/unit/check-redefine2.test | 8 ++++++++ test-data/unit/fixtures/primitives.pyi | 2 ++ 3 files changed, 18 insertions(+) diff --git a/test-data/unit/check-redefine.test b/test-data/unit/check-redefine.test index f760d0582a448..2f2b7bad72069 100644 --- a/test-data/unit/check-redefine.test +++ b/test-data/unit/check-redefine.test @@ -636,3 +636,11 @@ def _(arg: str) -> str: # E: Name "_" already defined (possibly by an import) [file a.py] def f(s: str) -> str: return s + +[case testRedefineListComprehension] +# flags: --allow-redefinition +def process(items: list[str]) -> None: + reveal_type(items) # N: Revealed type is "builtins.list[builtins.str]" + items = [item.split() for item in items] + reveal_type(items) # N: Revealed type is "builtins.list[builtins.list[builtins.str]]" +[builtins fixtures/primitives.pyi] diff --git a/test-data/unit/check-redefine2.test b/test-data/unit/check-redefine2.test index 6e9441151c935..8a6b871ce1279 100644 --- a/test-data/unit/check-redefine2.test +++ b/test-data/unit/check-redefine2.test @@ -1197,3 +1197,11 @@ x = 0 if int(): x = "" reveal_type(x) # N: Revealed type is "builtins.int | builtins.str" + +[case testNewRedefineListComprehension] +# flags: --allow-redefinition-new --local-partial-types +def process(items: list[str]) -> None: + reveal_type(items) # N: Revealed type is "builtins.list[builtins.str]" + items = [item.split() for item in items] + reveal_type(items) # N: Revealed type is "builtins.list[builtins.list[builtins.str]]" +[builtins fixtures/primitives.pyi] diff --git a/test-data/unit/fixtures/primitives.pyi b/test-data/unit/fixtures/primitives.pyi index fae4576639207..43ab5c90fd7a0 100644 --- a/test-data/unit/fixtures/primitives.pyi +++ b/test-data/unit/fixtures/primitives.pyi @@ -35,6 +35,8 @@ class str(Sequence[str]): def __contains__(self, other: object) -> bool: pass def __getitem__(self, item: int) -> str: pass def format(self, *args: object, **kwargs: object) -> str: pass + # Note: this is a simplification of the actual signature + def split(self, sep: str | None = None) -> list[str]: pass class bytes(Sequence[int]): def __iter__(self) -> Iterator[int]: pass def __contains__(self, other: object) -> bool: pass From a9a49bfeca75e77ca785ada9ce1c24740ce594ff Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Tue, 3 Feb 2026 08:36:04 -0500 Subject: [PATCH 2/2] xfail the failing test --- test-data/unit/check-redefine2.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-data/unit/check-redefine2.test b/test-data/unit/check-redefine2.test index 8a6b871ce1279..5d40e9731cd5e 100644 --- a/test-data/unit/check-redefine2.test +++ b/test-data/unit/check-redefine2.test @@ -1198,7 +1198,7 @@ if int(): x = "" reveal_type(x) # N: Revealed type is "builtins.int | builtins.str" -[case testNewRedefineListComprehension] +[case testNewRedefineListComprehension-xfail] # flags: --allow-redefinition-new --local-partial-types def process(items: list[str]) -> None: reveal_type(items) # N: Revealed type is "builtins.list[builtins.str]"