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 bug that led to an incorrect type evaluation for nested call ex…
…pressions where an inner call expression used a ParamSpec. This addresses microsoft#5281. (microsoft#5322) Co-authored-by: Eric Traut <[email protected]>
- Loading branch information
1 parent
b90abab
commit 2829429
Showing
4 changed files
with
65 additions
and
34 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
38 changes: 32 additions & 6 deletions
38
packages/pyright-internal/src/tests/samples/genericTypes108.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 |
---|---|---|
@@ -1,22 +1,48 @@ | ||
# This sample tests the handling of nested calls to generic functions | ||
# when bidirectional type inference is involved. | ||
|
||
from typing import Literal, TypeVar | ||
from typing import Callable, Generic, Literal, ParamSpec, TypeVar | ||
|
||
T = TypeVar("T") | ||
_T = TypeVar("_T") | ||
_P = ParamSpec("_P") | ||
|
||
|
||
def identity(x: T) -> T: | ||
def identity1(x: _T) -> _T: | ||
return x | ||
|
||
|
||
def identity2(x: T) -> T: | ||
def identity2(x: _T) -> _T: | ||
return x | ||
|
||
|
||
def test(x: Literal[2]) -> Literal[2]: | ||
return identity(identity2(x)) | ||
def test1(x: Literal[2]) -> Literal[2]: | ||
return identity1(identity2(x)) | ||
|
||
|
||
v1 = min(1, max(2, 0.5)) | ||
reveal_type(v1, expected_text="float") | ||
|
||
|
||
class Future(Generic[_T]): | ||
... | ||
|
||
|
||
def func1(future: Future[_T]) -> Future[_T]: | ||
... | ||
|
||
|
||
def func2(__fn: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> Future[_T]: | ||
... | ||
|
||
|
||
def func3() -> int: | ||
... | ||
|
||
|
||
def func4(a: int, b: int) -> str: | ||
... | ||
|
||
|
||
reveal_type(func1(func2(func3)), expected_text="Future[int]") | ||
reveal_type(func1(func2(func4, 1, 2)), expected_text="Future[str]") | ||
reveal_type(func1(func2(func4, a=1, b=2)), expected_text="Future[str]") |
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 |
---|---|---|
|
@@ -75,7 +75,6 @@ class A: | |
... | ||
|
||
|
||
T = TypeVar("T") | ||
T_A = TypeVar("T_A", bound=A) | ||
|
||
|
||
|