8000 Foundations for non-linear solver and polymorphic application by ilevkivskyi · Pull Request #15287 · python/mypy · GitHub 8000
[go: up one dir, main page]

Skip to content

Foundations for non-linear solver and polymorphic application #15287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make free variable choice stable
  • Loading branch information
ilevkivskyi committed Jun 5, 2023
commit fefe27ec45e68ebcefbce0ac1b02dbe30dabc56d
2 changes: 1 addition & 1 deletion mypy/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def solve_non_linear(
for c in cmap[tv]
):
# TODO: be careful about upper bounds (or values) when introducing free vars.
free_vars.append(next(tv for tv in scc))
free_vars.append(sorted(scc, key=lambda x: x.raw_id)[0])

# Flatten the SCCs that are independent, we can solve them together,
# since we don't need to update any targets in between.
Expand Down
12 changes: 6 additions & 6 deletions test-data/unit/check-generics.test
924D
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,7 @@ def dec(f: Callable[[S], T]) -> Callable[[S], List[T]]:
...
def id(x: U) -> U:
...
reveal_type(dec(id)) # N: Revealed type is "def [T] (T`2) -> builtins.list[T`2]"
reveal_type(dec(id)) # N: Revealed type is "def [S] (S`1) -> builtins.list[S`1]"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an actual use of the decorator to at least some of the decorator-like use cases, for more end-to-end testing? E.g. something like this:

@dec 
def f(...) -> ...: ...  # Generic function
reveal_type(f(...))

[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericCallableGenericReverse]
Expand Down Expand Up @@ -2830,7 +2830,7 @@ U = TypeVar('U')
def comb(f: Callable[[T], S], g: Callable[[S], U]) -> Callable[[T], U]: ...
def id(x: U) -> U:
...
reveal_type(comb(id, id)) # N: Revealed type is "def [S] (S`2) -> S`2"
reveal_type(comb(id, id)) # N: Revealed type is "def [T] (T`1) -> T`1"
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericCallableGenericNonLinear]
Expand All @@ -2849,7 +2849,7 @@ def mix(fs: List[Callable[[S], T]]) -> Callable[[S], List[T]]:
def id(__x: U) -> U:
...
fs = [id, id, id]
reveal_type(mix(fs)) # N: Revealed type is "def [T] (T`4) -> builtins.list[T`4]"
reveal_type(mix(fs)) # N: Revealed type is "def [S] (S`3) -> builtins.list[S`3]"
reveal_type(mix([id, id, id])) # N: Revealed type is "def [S] (S`5) -> builtins.list[S`5]"
[builtins fixtures/list.pyi]

Expand All @@ -2867,7 +2867,7 @@ def dec2(f: Callable[[T, U], S]) -> Callable[[U], Callable[[T], S]]: ...
def test1(x: V) -> V: ...
def test2(x: V, y: V) -> V: ...

reveal_type(dec1(test1)) # N: Revealed type is "def () -> def [S] (S`2) -> S`2"
reveal_type(dec1(test1)) # N: Revealed type is "def () -> def [T] (T`1) -> T`1"
# TODO: support this situation
reveal_type(dec2(test2)) # N: Revealed type is "def (builtins.object) -> def (builtins.object) -> builtins.object"
[builtins fixtures/paramspec.pyi]
Expand All @@ -2886,7 +2886,7 @@ def dec(f: A[S, T]) -> B[S, T]:
...
def id(x: U) -> U:
...
reveal_type(dec(id)) # N: Revealed type is "def [T] (T`2) -> builtins.list[T`2]"
reveal_type(dec(id)) # N: Revealed type is "def [S] (S`1) -> builtins.list[S`1]"
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericCallableGenericProtocol]
Expand Down Expand Up @@ -2933,5 +2933,5 @@ def dec(f: Callable[[T], S], g: Callable[[T], U]) -> Callable[[T], Tuple[S, U]]:
def id(x: V) -> V:
...

reveal_type(dec(id, id)) # N: Revealed type is "def [S] (S`2) -> Tuple[S`2, S`2]"
reveal_type(dec(id, id)) # N: Revealed type is "def [T] (T`1) -> Tuple[T`1, T`1]"
[builtins fixtures/tuple.pyi]
0