diff --git a/test-data/unit/check-redefine.test b/test-data/unit/check-redefine.test index f760d0582a44..2f2b7bad7206 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 6e9441151c93..8a6b871ce127 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 fae457663920..43ab5c90fd7a 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