forked from python/mypy
-
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.
Make PEP 695 constructs give a reasonable error message
Mypy does not yet support PEP 695 Fixes python#16011, linking python#15238
- Loading branch information
1 parent
2a6d9cb
commit 62a1a70
Showing
4 changed files
with
71 additions
and
1 deletion.
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,35 @@ | ||
[case test695TypeAlias] | ||
type MyInt = int # E: PEP 695 type aliases are not yet supported | ||
|
||
def f(x: MyInt) -> MyInt: | ||
return reveal_type(x) # N: Revealed type is "builtins.int" | ||
|
||
type MyList[T] = list[T] # E: PEP 695 type aliases are not yet supported \ | ||
# E: Name "T" is not defined | ||
|
||
def g(x: MyList[int]) -> MyList[int]: # E: Variable "__main__.MyList" is not valid as a type \ | ||
# N: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases | ||
return reveal_type(x) # N: Revealed type is "MyList?[builtins.int]" | ||
|
||
[case test695Class] | ||
class MyGen[T]: # E: PEP 695 generics are not yet supported | ||
def __init__(self, x: T) -> None: # E: Name "T" is not defined | ||
self.x = x | ||
|
||
def f(x: MyGen[int]): # E: "MyGen" expects no type arguments, but 1 given | ||
reveal_type(x.x) # N: Revealed type is "Any" | ||
|
||
[case test695Function] | ||
def f[T](x: T) -> T: # E: PEP 695 generics are not yet supported \ | ||
# E: Name "T" is not defined | ||
return reveal_type(x) # N: Revealed type is "Any" | ||
|
||
reveal_type(f(1)) # N: Revealed type is "Any" | ||
|
||
async def g[T](x: T) -> T: # E: PEP 695 generics are not yet supported \ | ||
# E: Name "T" is not defined | ||
return reveal_type(x) # N: Revealed type is "Any" | ||
|
||
reveal_type(g(1)) # E: Value of type "Coroutine[Any, Any, Any]" must be used \ | ||
# N: Are you missing an await? \ | ||
# N: Revealed type is "typing.Coroutine[Any, Any, Any]" |