-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add unbound typevar check #13166
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 23 commits into
python:master
from
AurelienJaquier:add-unbound-typevar-check
Jul 19, 2022
Merged
Add unbound typevar check #13166
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
cc8d33f
Add simple unbound typevar check and rudimentary test
cc8faff
Add test for unbound func returning iterables of TypeVars
a771393
Add appropriate error message and make the new test pass
714445e
add CollectArgTypes to get set of argument types
anilbey 595ec8c
Merge branch 'add-unbound-typevar-check' of github.com:AurelienJaquie…
anilbey db501a9
lint fix
anilbey e31f967
fix type error
anilbey 951a54d
extract check_unbound_return_typevar as method
anilbey b9b1561
check if return type is instantiated in typ.variables
anilbey 0335cc1
Fix some tests that are affected by new implementation
0cf8e93
Merge branch 'add-unbound-typevar-check' of https://github.com/Aureli…
1ddf301
add testInnerFunctionTypeVar test
anilbey 32c0c84
fix testErrorCodeNeedTypeAnnotation test
1175d53
add TYPE_VAR error code to unbound error failure
anilbey f1a27d1
Merge branch 'add-unbound-typevar-check' of https://github.com/Aureli…
402a4e3
Fix the tests
34dc475
move new tests in new test file
b78b926
add 'check-typevar-unbound.test' to testcheck
anilbey ce9ceaf
add more nested tests for unbound type
anilbey 64b1834
microoptimise check_unbound_return_typevar check ret_type first
anilbey 0ff4b12
Merge branch 'master' into add-unbound-typevar-check
ilevkivskyi 4352bc3
add missing builtins fixture to failing test
anilbey abb6f1c
Merge branch 'add-unbound-typevar-check' of github.com:AurelienJaquie…
anilbey 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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
[case testUnboundTypeVar] | ||
from typing import TypeVar | ||
|
||
T = TypeVar('T') | ||
|
||
def f() -> T: # E: A function returning TypeVar should receive at least one argument containing the same Typevar | ||
... | ||
|
||
f() | ||
|
||
|
||
[case testInnerFunctionTypeVar] | ||
|
||
from typing import TypeVar | ||
|
||
T = TypeVar('T') | ||
|
||
def g(a: T) -> T: | ||
def f() -> T: | ||
... | ||
return f() | ||
|
||
|
||
[case testUnboundIterableOfTypeVars] | ||
from typing import Iterable, TypeVar | ||
|
||
T = TypeVar('T') | ||
|
||
def f() -> Iterable[T]: | ||
... | ||
|
||
f() | ||
|
||
[case testBoundTypeVar] | ||
from typing import TypeVar | ||
|
||
T = TypeVar('T') | ||
|
||
def f(a: T, b: T, c: int) -> T: | ||
... | ||
|
||
|
||
[case testNestedBoundTypeVar] | ||
from typing import Callable, List, Union, Tuple, TypeVar | ||
|
||
T = TypeVar('T') | ||
|
||
def f(a: Union[int, T], b: str) -> T: | ||
... | ||
|
||
def g(a: Callable[..., T], b: str) -> T: | ||
... | ||
|
||
def h(a: List[Union[Callable[..., T]]]) -> T: | ||
... | ||
|
||
def j(a: List[Union[Callable[..., Tuple[T, T]], int]]) -> T: | ||
... | ||
[builtins fixtures/tuple.pyi] |
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.
could you add one more test case with something more nested, say List[Union[Callable[..., Tuple[T]]]]
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.
Done with the last push.