forked from microsoft/pyright
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed false negative when a literal and non-literal are assigned to t…
…he same TypeVar in an invariant context. This addresses microsoft#5321. (microsoft#5323) Co-authored-by: Eric Traut <[email protected]>
- Loading branch information
1 parent
2829429
commit 0559382
Showing
7 changed files
with
110 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/pyright-internal/src/tests/samples/genericTypes117.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This sample validates that a literal and a non-literal are not considered | ||
# compatible types when in an invariant context. | ||
|
||
from typing import Literal, TypeVar | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
def func1(a: T, b: T) -> T: | ||
return a | ||
|
||
|
||
def func2() -> None: | ||
foo_list: list[Literal["foo"]] = ["foo"] | ||
x = func1(foo_list, [""]) | ||
reveal_type(x, expected_text="list[Literal['foo']] | list[str]") | ||
|
||
# This should generate an error. | ||
x.append("not foo") | ||
print(foo_list) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters