-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
ilevkivskyi
merged 19 commits into
python:master
from
ilevkivskyi:fix-generic-inference
Jun 18, 2023
+998
−193
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
08a8815
Start working on generic stuff
ilevkivskyi eb3a1e1
Make some progress
ilevkivskyi 52209c9
Add/reorganize tests
ilevkivskyi a64183d
Solve in topological order
8000
ilevkivskyi 9191761
Delete tests that are not going to be supported
ilevkivskyi ba0f252
Support type aliases; more tests
ilevkivskyi 8eb04a9
Support callback protocols; more tests
ilevkivskyi ec8b695
Add some docstring/comments
ilevkivskyi d5eb5fa
Merge remote-tracking branch 'upstream/master' into fix-generic-infer…
ilevkivskyi 4c41c67
Some tweaks
ilevkivskyi 163720c
Minor fixes
ilevkivskyi 0bc41b0
Fix bugs
ilevkivskyi fefe27e
Make free variable choice stable
ilevkivskyi 4aca3ba
Special-case a corner case
ilevkivskyi 42cc4cf
Make self-type special-casing wider
ilevkivskyi d0a3d0d
Merge remote-tracking branch 'upstream/master' into fix-generic-infer…
ilevkivskyi 47db859
Temporary flag to hide new inference
ilevkivskyi 96d0f39
Merge remote-tracking branch 'upstream/master' into fix-generic-infer…
ilevkivskyi 66b4567
Address CR
ilevkivskyi File filter
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
Address CR
- Loading branch information
commit 66b4567aa36ae9d4429003e4106db1284d1178e4
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -2734,6 +2734,9 @@ dict2 = {"a": C1(), **{x: C2() for x in dict1}} | |
reveal_type(dict2) # N: Revealed type is "builtins.dict[Any, __main__.B]" | ||
[builtins fixtures/dict.pyi] | ||
|
||
-- Type inference for generic decorators applied to generic callables | ||
-- ------------------------------------------------------------------ | ||
|
||
[case testInferenceAgainstGenericCallable] | ||
# flags: --new-type-inference | ||
from typing import TypeVar, Callable, List | ||
|
@@ -2794,6 +2797,12 @@ def dec(f: Callable[[S], T]) -> Callable[[S], List[T]]: | |
def id(x: U) -> U: | ||
... | ||
reveal_type(dec(id)) # N: Revealed type is "def [S] (S`1) -> builtins.list[S`1]" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(...)) |
||
|
||
@dec | ||
def same(x: U) -> U: | ||
... | ||
reveal_type(same) # N: Revealed type is "def [S] (S`3) -> builtins.list[S`3]" | ||
reveal_type(same(42)) # N: Revealed type is "builtins.list[builtins.int]" | ||
[builtins fixtures/list.pyi] | ||
|
||
[case testInferenceAgainstGenericCallableGenericReverse] | ||
|
@@ -2809,6 +2818,12 @@ def dec(f: Callable[[S], List[T]]) -> Callable[[S], T]: | |
def id(x: U) -> U: | ||
... | ||
reveal_type(dec(id)) # N: Revealed type is "def [T] (builtins.list[T`2]) -> T`2" | ||
|
||
@dec | ||
def same(x: U) -> U: | ||
... | ||
reveal_type(same) # N: Revealed type is "def [T] (builtins.list[T`4]) -> T`4" | ||
reveal_type(same([42])) # N: Revealed type is "builtins.int" | ||
[builtins fixtures/list.pyi] | ||
|
||
[case testInferenceAgainstGenericCallableGenericArg] | ||
|
@@ -2824,6 +2839,12 @@ def dec(f: Callable[[S], T]) -> Callable[[S], T]: | |
def test(x: U) -> List[U]: | ||
... | ||
reveal_type(dec(test)) # N: Revealed type is "def [S] (S`1) -> builtins.list[S`1]" | ||
|
||
@dec | ||
def single(x: U) -> List[U]: | ||
... | ||
reveal_type(single) # N: Revealed type is "def [S] (S`3) -> builtins.list[S`3]" | ||
reveal_type(single(42)) # N: Revealed type is "builtins.list[builtins.int]" | ||
[builtins fixtures/list.pyi] | ||
|
||
[case testInferenceAgainstGenericCallableGenericChain] | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment here about the purpose of this if statement (I think I figured it out but it wasn't obvious).