-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic support for typing_extensions.Annotated. (#7292)
Closes #7021. This adds basic support for `typing_extensions.Annotated`. Currently, we just discard all annotations and resolve to the inner type. Plugins can use `get_type_analyze_hook` to try to intervene before this step, but most of the arguments that aren't just names or `Literal`-able values will have already been mangled by this point. Nothing other than the type sees any sort of validation, either. See the issue discussion for more on this.
- Loading branch information
1 parent
e0a5b2e
commit f67c3ee
Showing
5 changed files
with
82 additions
and
0 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,65 @@ | ||
[case testAnnotated0] | ||
from typing_extensions import Annotated | ||
x: Annotated[int, ...] | ||
reveal_type(x) # N: Revealed type is 'builtins.int' | ||
|
||
[case testAnnotated1] | ||
from typing import Union | ||
from typing_extensions import Annotated | ||
x: Annotated[Union[int, str], ...] | ||
reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' | ||
|
||
[case testAnnotated2] | ||
from typing_extensions import Annotated | ||
x: Annotated[int, THESE, ARE, IGNORED, FOR, NOW] | ||
reveal_type(x) # N: Revealed type is 'builtins.int' | ||
|
||
[case testAnnotated3] | ||
from typing_extensions import Annotated | ||
x: Annotated[int, -+~12.3, "som"[e], more(anno+a+ions, that=[are]), (b"ignored",), 4, N.O.W, ...] | ||
reveal_type(x) # N: Revealed type is 'builtins.int' | ||
|
||
[case testAnnotatedBadType] | ||
from typing_extensions import Annotated | ||
x: Annotated[XXX, ...] # E: Name 'XXX' is not defined | ||
reveal_type(x) # N: Revealed type is 'Any' | ||
|
||
[case testAnnotatedBadNoArgs] | ||
from typing_extensions import Annotated | ||
x: Annotated # E: Annotated[...] must have exactly one type argument and at least one annotation | ||
reveal_type(x) # N: Revealed type is 'Any' | ||
|
||
[case testAnnotatedBadOneArg] | ||
from typing_extensions import Annotated | ||
x: Annotated[int] # E: Annotated[...] must have exactly one type argument and at least one annotation | ||
reveal_type(x) # N: Revealed type is 'Any' | ||
|
||
[case testAnnotatedNested0] | ||
from typing_extensions import Annotated | ||
x: Annotated[Annotated[int, ...], ...] | ||
reveal_type(x) # N: Revealed type is 'builtins.int' | ||
|
||
[case testAnnotatedNested1] | ||
from typing import Union | ||
from typing_extensions import Annotated | ||
x: Annotated[Annotated[Union[int, str], ...], ...] | ||
reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' | ||
|
||
[case testAnnotatedNestedBadType] | ||
from typing_extensions import Annotated | ||
x: Annotated[Annotated[XXX, ...], ...] # E: Name 'XXX' is not defined | ||
reveal_type(x) # N: Revealed type is 'Any' | ||
|
||
[case testAnnotatedNestedBadNoArgs] | ||
from typing_extensions import Annotated | ||
x: Annotated[Annotated, ...] # E: Annotated[...] must have exactly one type argument and at least one annotation | ||
reveal_type(x) # N: Revealed type is 'Any' | ||
|
||
[case testAnnotatedNestedBadOneArg] | ||
from typing_extensions import Annotated | ||
x: Annotated[Annotated[int], ...] # E: Annotated[...] must have exactly one type argument and at least one annotation | ||
reveal_type(x) # N: Revealed type is 'Any' | ||
|
||
[case testAnnotatedNoImport] | ||
x: Annotated[int, ...] # E: Name 'Annotated' is not defined | ||
reveal_type(x) # N: Revealed type is 'Any' |
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