[red-knot] Emit an error if a bare Annotated or Literal is used in a type expression (#14973)

This commit is contained in:
Alex Waygood
2024-12-15 02:00:52 +00:00
committed by GitHub
parent fa46ba2306
commit 1389cb8e59
4 changed files with 135 additions and 23 deletions

View File

@@ -29,10 +29,24 @@ It is invalid to parameterize `Annotated` with less than two arguments.
```py
from typing_extensions import Annotated
# TODO: This should be an error
# error: [invalid-type-form] "`Annotated` requires at least two arguments when used in an annotation or type expression"
def _(x: Annotated):
reveal_type(x) # revealed: Unknown
def _(flag: bool):
if flag:
X = Annotated
else:
X = bool
# error: [invalid-type-form] "`Annotated` requires at least two arguments when used in an annotation or type expression"
def f(y: X):
reveal_type(y) # revealed: Unknown | bool
# error: [invalid-type-form] "`Annotated` requires at least two arguments when used in an annotation or type expression"
def _(x: Annotated | bool):
reveal_type(x) # revealed: Unknown | bool
# error: [invalid-type-form]
def _(x: Annotated[()]):
reveal_type(x) # revealed: Unknown