Skip to content

Commit eba24b4

Browse files
authored
(minor) make PEP 612 wip locations more greppable (#11311)
Co-authored-by: hauntsaninja <>
1 parent 8cba3bc commit eba24b4

9 files changed

+36
-53
lines changed

mypy/applytype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def get_target_type(
1818
context: Context,
1919
skip_unsatisfied: bool
2020
) -> Optional[Type]:
21-
# TODO(shantanu): fix for ParamSpecType
21+
# TODO(PEP612): fix for ParamSpecType
2222
if isinstance(tvar, ParamSpecType):
2323
return None
2424
assert isinstance(tvar, TypeVarType)

mypy/checker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ def expand_typevars(self, defn: FuncItem,
14151415
if defn.info:
14161416
# Class type variables
14171417
tvars += defn.info.defn.type_vars or []
1418-
# TODO(shantanu): audit for paramspec
1418+
# TODO(PEP612): audit for paramspec
14191419
for tvar in tvars:
14201420
if isinstance(tvar, TypeVarType) and tvar.values:
14211421
subst.append([(tvar.id, value) for value in tvar.values])

mypy/checkexpr.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4476,7 +4476,7 @@ def merge_typevars_in_callables_by_name(
44764476
for tv in target.variables:
44774477
name = tv.fullname
44784478
if name not in unique_typevars:
4479-
# TODO(shantanu): fix for ParamSpecType
4479+
# TODO(PEP612): fix for ParamSpecType
44804480
if isinstance(tv, ParamSpecType):
44814481
continue
44824482
assert isinstance(tv, TypeVarType)

mypy/expandtype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def freshen_function_type_vars(callee: F) -> F:
4141
tvs = []
4242
tvmap: Dict[TypeVarId, Type] = {}
4343
for v in callee.variables:
44-
# TODO(shantanu): fix for ParamSpecType
44+
# TODO(PEP612): fix for ParamSpecType
4545
if isinstance(v, ParamSpecType):
4646
continue
4747
assert isinstance(v, TypeVarType)

mypy/semanal.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1327,8 +1327,8 @@ class Foo(Bar, Generic[T]): ...
13271327
for name, tvar_expr in declared_tvars:
13281328
tvar_def = self.tvar_scope.bind_new(name, tvar_expr)
13291329
if isinstance(tvar_def, TypeVarType):
1330-
# This can also be `ParamSpecType`,
1331-
# error will be reported elsewhere: #11218
1330+
# TODO(PEP612): fix for ParamSpecType
1331+
# Error will be reported elsewhere: #11218
13321332
tvar_defs.append(tvar_def)
13331333
return base_type_exprs, tvar_defs, is_protocol
13341334

mypy/typeanal.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ def analyze_callable_args_for_paramspec(
692692
if not isinstance(tvar_def, ParamSpecType):
693693
return None
694694

695-
# TODO(shantanu): construct correct type for paramspec
695+
# TODO(PEP612): construct correct type for paramspec
696696
return CallableType(
697697
[AnyType(TypeOfAny.explicit), AnyType(TypeOfAny.explicit)],
698698
[nodes.ARG_STAR, nodes.ARG_STAR2],
@@ -745,7 +745,7 @@ def analyze_callable_type(self, t: UnboundType) -> Type:
745745
)
746746
if maybe_ret is None:
747747
# Callable[?, RET] (where ? is something invalid)
748-
# TODO(shantanu): change error to mention paramspec, once we actually have some
748+
# TODO(PEP612): change error to mention paramspec, once we actually have some
749749
# support for it
750750
self.fail('The first argument to Callable must be a list of types or "..."', t)
751751
return AnyType(TypeOfAny.from_error)

mypy/typeops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def true_or_false(t: Type) -> ProperType:
511511

512512

513513
def erase_def_to_union_or_bound(tdef: TypeVarLikeType) -> Type:
514-
# TODO(shantanu): fix for ParamSpecType
514+
# TODO(PEP612): fix for ParamSpecType
515515
if isinstance(tdef, ParamSpecType):
516516
return AnyType(TypeOfAny.from_error)
517517
assert isinstance(tdef, TypeVarType)

test-data/unit/check-parameter-specification.test

+27-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def foo1(x: Callable[P, int]) -> Callable[P, str]: ...
1515
def foo2(x: P) -> P: ... # E: Invalid location for ParamSpec "P" \
1616
# N: You can use ParamSpec as the first argument to Callable, e.g., 'Callable[P, int]'
1717

18-
# TODO(shantanu): uncomment once we have support for Concatenate
18+
# TODO(PEP612): uncomment once we have support for Concatenate
1919
# def foo3(x: Concatenate[int, P]) -> int: ... $ E: Invalid location for Concatenate
2020

2121
def foo4(x: List[P]) -> None: ... # E: Invalid location for ParamSpec "P" \
@@ -29,6 +29,7 @@ def foo6(x: Callable[[P], int]) -> None: ... # E: Invalid location for ParamSpe
2929
[builtins fixtures/tuple.pyi]
3030

3131
[case testParamSpecTemporaryAnyBehaviour]
32+
# TODO(PEP612): behaviour tested here should change
3233
# This is a test of mypy's temporary behaviour in lieu of full support for ParamSpec
3334
from typing import Callable, List, Iterator, TypeVar
3435
from typing_extensions import ParamSpec
@@ -50,3 +51,28 @@ def whatever(x: int) -> Iterator[int]:
5051
reveal_type(whatever) # N: Revealed type is "def (*Any, **Any) -> builtins.list[builtins.int*]"
5152
reveal_type(whatever(217)) # N: Revealed type is "builtins.list[builtins.int*]"
5253
[builtins fixtures/tuple.pyi]
54+
55+
[case testGenericParamSpecTemporaryBehaviour]
56+
# flags: --python-version 3.10
57+
# TODO(PEP612): behaviour tested here should change
58+
from typing import Generic, TypeVar, Callable, ParamSpec
59+
60+
T = TypeVar("T")
61+
P = ParamSpec("P")
62+
63+
class X(Generic[T, P]): # E: Free type variable expected in Generic[...]
64+
f: Callable[P, int] # E: The first argument to Callable must be a list of types or "..."
65+
x: T
66+
[out]
67+
68+
[case testInvalidParamSpecType]
69+
# flags: --python-version 3.10
70+
from typing import ParamSpec
71+
72+
P = ParamSpec("P")
73+
74+
class MyFunction(P): # E: Invalid location for ParamSpec "P" \
75+
# N: You can use ParamSpec as the first argument to Callable, e.g., 'Callable[P, int]'
76+
...
77+
78+
a: MyFunction[int] # E: "MyFunction" expects no type arguments, but 1 given

test-data/unit/semanal-errors.test

-43
Original file line numberDiff line numberDiff line change
@@ -41,49 +41,6 @@ x = None # type: X
4141
[out]
4242
main:2: error: Name "X" is not defined
4343

44-
[case testInvalidParamSpecType1]
45-
# flags: --python-version 3.10
46-
from typing import ParamSpec
47-
48-
P = ParamSpec("P")
49-
50-
class MyFunction(P):
51-
...
52-
53-
a: MyFunction[int]
54-
[out]
55-
main:6: error: Invalid location for ParamSpec "P"
56-
main:6: note: You can use ParamSpec as the first argument to Callable, e.g., 'Callable[P, int]'
57-
main:9: error: "MyFunction" expects no type arguments, but 1 given
58-
59-
[case testInvalidParamSpecType2]
60-
from typing_extensions import ParamSpec
61-
62-
P = ParamSpec("P")
63-
64-
class MyFunction(P):
65-
...
66-
67-
a: MyFunction[int]
68-
[out]
69-
main:5: error: Invalid location for ParamSpec "P"
70-
main:5: note: You can use ParamSpec as the first argument to Callable, e.g., 'Callable[P, int]'
71-
main:8: error: "MyFunction" expects no type arguments, but 1 given
72-
73-
[case testGenericParamSpec]
74-
# flags: --python-version 3.10
75-
from typing import Generic, TypeVar, Callable, ParamSpec
76-
77-
T = TypeVar("T")
78-
P = ParamSpec("P")
79-
80-
class X(Generic[T, P]):
81-
f: Callable[P, int]
82-
x: T
83-
[out]
84-
main:7: error: Free type variable expected in Generic[...]
85-
main:8: error: The first argument to Callable must be a list of types or "..."
86-
8744
[case testInvalidGenericArg]
8845
from typing import TypeVar, Generic
8946
t = TypeVar('t')

0 commit comments

Comments
 (0)