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 a bug that led to a false positive error under certain circumst…
…ances when a literal type argument was used in conjunction with a protocol that used a covariant type parameter and an implementation of that protocol that used an invariant type parameter. This addresses microsoft#5282. (microsoft#5332) Co-authored-by: Eric Traut <erictr@microsoft.com>
- Loading branch information
1 parent
2b0f8d2
commit e3080b1
Showing
3 changed files
with
35 additions
and
1 deletion.
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
28 changes: 28 additions & 0 deletions
28
packages/pyright-internal/src/tests/samples/genericTypes119.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,28 @@ | ||
# This sample tests the case where a protocol uses a covariant | ||
# type parameter but a corresponding implementation uses an | ||
# invariant type parameter. Literal types need to be handled | ||
# carefully in this case. | ||
|
||
from typing import Awaitable, Literal, TypeVar | ||
|
||
_T = TypeVar("_T") | ||
|
||
|
||
class Future(Awaitable[_T]): | ||
... | ||
|
||
|
||
def func1(future: Future[_T]) -> Future[_T]: | ||
... | ||
|
||
|
||
def func2(coro: Awaitable[_T]) -> Future[_T]: | ||
... | ||
|
||
|
||
def func3() -> Awaitable[Literal[True]]: | ||
... | ||
|
||
|
||
v1 = func1(func2(func3())) | ||
reveal_type(v1, expected_text="Future[Literal[True]]") |
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