-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Further simplification of the logic involved in type var solving.
- Loading branch information
Showing
7 changed files
with
101 additions
and
66 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
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,26 @@ | ||
# This sample tests a complex TypeVar unification scenario. | ||
|
||
from typing import Callable, Generic, TypeVar | ||
|
||
A = TypeVar("A") | ||
B = TypeVar("B") | ||
|
||
|
||
class Gen(Generic[A]): | ||
... | ||
|
||
|
||
def func1(x: A) -> A: | ||
... | ||
|
||
|
||
def func2(x: Gen[A], y: A) -> Gen[Gen[A]]: | ||
... | ||
|
||
|
||
def func3(x: Gen[Gen[A]]) -> Gen[A]: | ||
return func4(x, func1, func2) | ||
|
||
|
||
def func4(x: Gen[A], id_: Callable[[B], B], step: Callable[[A, B], Gen[A]]) -> A: | ||
... |
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,42 @@ | ||
# This sample tests a complex TypeVar unification scenario. | ||
|
||
from typing import Protocol, TypeVar | ||
|
||
A = TypeVar("A", contravariant=True) | ||
B = TypeVar("B", covariant=True) | ||
T = TypeVar("T") | ||
U = TypeVar("U") | ||
V = TypeVar("V") | ||
|
||
|
||
class Getter(Protocol[A, B]): | ||
def __call__(self, x: A, /) -> B: | ||
... | ||
|
||
|
||
class PolymorphicListItemGetter(Protocol): | ||
def __call__(self, l: list[T], /) -> T: | ||
... | ||
|
||
|
||
def compose(get1: Getter[T, U], get2: Getter[U, V]) -> Getter[T, V]: | ||
... | ||
|
||
|
||
class HasMethod(Protocol): | ||
@property | ||
def method(self) -> int: | ||
... | ||
|
||
|
||
def get_value(x: HasMethod) -> int: | ||
... | ||
|
||
|
||
def upcast(x: PolymorphicListItemGetter) -> Getter[list[HasMethod], HasMethod]: | ||
return x | ||
|
||
|
||
def test(poly_getter: PolymorphicListItemGetter): | ||
compose(poly_getter, get_value) | ||
compose(upcast(poly_getter), get_value) |
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