Skip to content

Commit 710aa13

Browse files
add test for 19918: our example code
1 parent 5af25ce commit 710aa13

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

test-data/unit/check-redefine.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,3 +636,11 @@ def _(arg: str) -> str: # E: Name "_" already defined (possibly by an import)
636636
[file a.py]
637637
def f(s: str) -> str:
638638
return s
639+
640+
[case testRedefineListComprehension]
641+
# flags: --allow-redefinition
642+
def process(items: list[str]) -> None:
643+
reveal_type(items) # N: Revealed type is "builtins.list[builtins.str]"
644+
items = [item.split() for item in items]
645+
reveal_type(items) # N: Revealed type is "builtins.list[builtins.list[builtins.str]]"
646+
[builtins fixtures/primitives.pyi]

test-data/unit/check-redefine2.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,3 +1197,11 @@ x = 0
11971197
if int():
11981198
x = ""
11991199
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str"
1200+
1201+
[case testNewRedefineListComprehension]
1202+
# flags: --allow-redefinition-new --local-partial-types
1203+
def process(items: list[str]) -> None:
1204+
reveal_type(items) # N: Revealed type is "builtins.list[builtins.str]"
1205+
items = [item.split() for item in items]
1206+
reveal_type(items) # N: Revealed type is "builtins.list[builtins.list[builtins.str]]"
1207+
[builtins fixtures/primitives.pyi]

test-data/unit/fixtures/primitives.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class str(Sequence[str]):
3535
def __contains__(self, other: object) -> bool: pass
3636
def __getitem__(self, item: int) -> str: pass
3737
def format(self, *args: object, **kwargs: object) -> str: pass
38+
# Note: this is a simplification of the actual signature
39+
def split(self, sep: str | None = None) -> list[str]: pass
3840
class bytes(Sequence[int]):
3941
def __iter__(self) -> Iterator[int]: pass
4042
def __contains__(self, other: object) -> bool: pass

0 commit comments

Comments
 (0)