Skip to content

Commit

Permalink
Mention --enable-incomplete-feature=NewGenericSyntax
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Jul 1, 2024
1 parent 4ae632b commit 65afb94
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
16 changes: 13 additions & 3 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,9 @@ def do_func_def(
else:
self.fail(
ErrorMessage(
"PEP 695 generics are not yet supported", code=codes.VALID_TYPE
"PEP 695 generics are not yet supported. "
"Use --enable-incomplete-feature=NewGenericSyntax for experimental support",
code=codes.VALID_TYPE,
),
n.type_params[0].lineno,
n.type_params[0].col_offset,
Expand Down Expand Up @@ -1145,7 +1147,11 @@ def visit_ClassDef(self, n: ast3.ClassDef) -> ClassDef:
explicit_type_params = self.translate_type_params(n.type_params)
else:
self.fail(
ErrorMessage("PEP 695 generics are not yet supported", code=codes.VALID_TYPE),
ErrorMessage(
"PEP 695 generics are not yet supported. "
"Use --enable-incomplete-feature=NewGenericSyntax for experimental support",
code=codes.VALID_TYPE,
),
n.type_params[0].lineno,
n.type_params[0].col_offset,
blocker=False,
Expand Down Expand Up @@ -1801,7 +1807,11 @@ def visit_TypeAlias(self, n: ast_TypeAlias) -> TypeAliasStmt | AssignmentStmt:
return self.set_line(node, n)
else:
self.fail(
ErrorMessage("PEP 695 type aliases are not yet supported", code=codes.VALID_TYPE),
ErrorMessage(
"PEP 695 type aliases are not yet supported. "
"Use --enable-incomplete-feature=NewGenericSyntax for experimental support",
code=codes.VALID_TYPE,
),
n.lineno,
n.col_offset,
blocker=False,
Expand Down
28 changes: 14 additions & 14 deletions test-data/unit/check-python312.test
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[case test695TypeAlias]
type MyInt = int # E: PEP 695 type aliases are not yet supported
type MyInt = int # E: PEP 695 type aliases are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support

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 \
type MyList[T] = list[T] # E: PEP 695 type aliases are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support \
# E: Name "T" is not defined

def g(x: MyList[int]) -> MyList[int]: # E: Variable "__main__.MyList" is not valid as a type \
Expand All @@ -17,21 +17,21 @@ def h(x: MyInt2) -> MyInt2:
return reveal_type(x) # N: Revealed type is "builtins.int"

[case test695Class]
class MyGen[T]: # E: PEP 695 generics are not yet supported
class MyGen[T]: # E: PEP 695 generics are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support
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 \
def f[T](x: T) -> T: # E: PEP 695 generics are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support \
# 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 \
async def g[T](x: T) -> T: # E: PEP 695 generics are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support \
# E: Name "T" is not defined
return reveal_type(x) # N: Revealed type is "Any"

Expand All @@ -41,26 +41,26 @@ reveal_type(g(1)) # E: Value of type "Coroutine[Any, Any, Any]" must be used \

[case test695TypeVar]
from typing import Callable
type Alias1[T: int] = list[T] # E: PEP 695 type aliases are not yet supported \
type Alias1[T: int] = list[T] # E: PEP 695 type aliases are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support \
# E: Name "T" is not defined
type Alias2[**P] = Callable[P, int] # E: PEP 695 type aliases are not yet supported \
type Alias2[**P] = Callable[P, int] # E: PEP 695 type aliases are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support \
# E: Value of type "int" is not indexable \
# E: Name "P" is not defined
type Alias3[*Ts] = tuple[*Ts] # E: PEP 695 type aliases are not yet supported \
type Alias3[*Ts] = tuple[*Ts] # E: PEP 695 type aliases are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support \
# E: Name "Ts" is not defined

class Cls1[T: int]: ... # E: PEP 695 generics are not yet supported
class Cls2[**P]: ... # E: PEP 695 generics are not yet supported
class Cls3[*Ts]: ... # E: PEP 695 generics are not yet supported
class Cls1[T: int]: ... # E: PEP 695 generics are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support
class Cls2[**P]: ... # E: PEP 695 generics are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support
class Cls3[*Ts]: ... # E: PEP 695 generics are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support

def func1[T: int](x: T) -> T: ... # E: PEP 695 generics are not yet supported \
def func1[T: int](x: T) -> T: ... # E: PEP 695 generics are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support \
# E: Name "T" is not defined

def func2[**P](x: Callable[P, int]) -> Callable[P, str]: ... # E: PEP 695 generics are not yet supported \
def func2[**P](x: Callable[P, int]) -> Callable[P, str]: ... # E: PEP 695 generics are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support \
# E: The first argument to Callable must be a list of types, parameter specification, or "..." \
# N: See https://mypy.readthedocs.io/en/stable/kinds_of_types.html#callable-types-and-lambdas \
# E: Name "P" is not defined
def func3[*Ts](x: tuple[*Ts]) -> tuple[int, *Ts]: ... # E: PEP 695 generics are not yet supported \
def func3[*Ts](x: tuple[*Ts]) -> tuple[int, *Ts]: ... # E: PEP 695 generics are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support \
# E: Name "Ts" is not defined
[builtins fixtures/tuple.pyi]

Expand Down

0 comments on commit 65afb94

Please sign in to comment.