Skip to content

(minor) make PEP 612 wip locations more greppable #11311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/applytype.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_target_type(
context: Context,
skip_unsatisfied: bool
) -> Optional[Type]:
# TODO(shantanu): fix for ParamSpecType
# TODO(PEP612): fix for ParamSpecType
if isinstance(tvar, ParamSpecType):
return None
assert isinstance(tvar, TypeVarType)
Expand Down
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ def expand_typevars(self, defn: FuncItem,
if defn.info:
# Class type variables
tvars += defn.info.defn.type_vars or []
# TODO(shantanu): audit for paramspec
# TODO(PEP612): audit for paramspec
for tvar in tvars:
if isinstance(tvar, TypeVarType) and tvar.values:
subst.append([(tvar.id, value) for value in tvar.values])
Expand Down
2 changes: 1 addition & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4477,7 +4477,7 @@ def merge_typevars_in_callables_by_name(
for tv in target.variables:
name = tv.fullname
if name not in unique_typevars:
# TODO(shantanu): fix for ParamSpecType
# TODO(PEP612): fix for ParamSpecType
if isinstance(tv, ParamSpecType):
continue
assert isinstance(tv, TypeVarType)
Expand Down
2 changes: 1 addition & 1 deletion mypy/expandtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def freshen_function_type_vars(callee: F) -> F:
tvs = []
tvmap: Dict[TypeVarId, Type] = {}
for v in callee.variables:
# TODO(shantanu): fix for ParamSpecType
# TODO(PEP612): fix for ParamSpecType
if isinstance(v, ParamSpecType):
continue
assert isinstance(v, TypeVarType)
Expand Down
4 changes: 2 additions & 2 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,8 +1327,8 @@ class Foo(Bar, Generic[T]): ...
for name, tvar_expr in declared_tvars:
tvar_def = self.tvar_scope.bind_new(name, tvar_expr)
if isinstance(tvar_def, TypeVarType):
# This can also be `ParamSpecType`,
# error will be reported elsewhere: #11218
# TODO(PEP612): fix for ParamSpecType
# Error will be reported elsewhere: #11218
tvar_defs.append(tvar_def)
return base_type_exprs, tvar_defs, is_protocol

Expand Down
4 changes: 2 additions & 2 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def analyze_callable_args_for_paramspec(
if not isinstance(tvar_def, ParamSpecType):
return None

# TODO(shantanu): construct correct type for paramspec
# TODO(PEP612): construct correct type for paramspec
return CallableType(
[AnyType(TypeOfAny.explicit), AnyType(TypeOfAny.explicit)],
[nodes.ARG_STAR, nodes.ARG_STAR2],
Expand Down Expand Up @@ -745,7 +745,7 @@ def analyze_callable_type(self, t: UnboundType) -> Type:
)
if maybe_ret is None:
# Callable[?, RET] (where ? is something invalid)
# TODO(shantanu): change error to mention paramspec, once we actually have some
# TODO(PEP612): change error to mention paramspec, once we actually have some
# support for it
self.fail('The first argument to Callable must be a list of types or "..."', t)
return AnyType(TypeOfAny.from_error)
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeops.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def true_or_false(t: Type) -> ProperType:


def erase_def_to_union_or_bound(tdef: TypeVarLikeType) -> Type:
# TODO(shantanu): fix for ParamSpecType
# TODO(PEP612): fix for ParamSpecType
if isinstance(tdef, ParamSpecType):
return AnyType(TypeOfAny.from_error)
assert isinstance(tdef, TypeVarType)
Expand Down
28 changes: 27 additions & 1 deletion test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def foo1(x: Callable[P, int]) -> Callable[P, str]: ...
def foo2(x: P) -> P: ... # E: Invalid location for ParamSpec "P" \
# N: You can use ParamSpec as the first argument to Callable, e.g., 'Callable[P, int]'

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

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

[case testParamSpecTemporaryAnyBehaviour]
# TODO(PEP612): behaviour tested here should change
# This is a test of mypy's temporary behaviour in lieu of full support for ParamSpec
from typing import Callable, List, Iterator, TypeVar
from typing_extensions import ParamSpec
Expand All @@ -50,3 +51,28 @@ def whatever(x: int) -> Iterator[int]:
reveal_type(whatever) # N: Revealed type is "def (*Any, **Any) -> builtins.list[builtins.int*]"
reveal_type(whatever(217)) # N: Revealed type is "builtins.list[builtins.int*]"
[builtins fixtures/tuple.pyi]

[case testGenericParamSpecTemporaryBehaviour]
# flags: --python-version 3.10
# TODO(PEP612): behaviour tested here should change
from typing import Generic, TypeVar, Callable, ParamSpec

T = TypeVar("T")
P = ParamSpec("P")

class X(Generic[T, P]): # E: Free type variable expected in Generic[...]
f: Callable[P, int] # E: The first argument to Callable must be a list of types or "..."
x: T
[out]

[case testInvalidParamSpecType]
# flags: --python-version 3.10
from typing import ParamSpec

P = ParamSpec("P")

class MyFunction(P): # E: Invalid location for ParamSpec "P" \
# N: You can use ParamSpec as the first argument to Callable, e.g., 'Callable[P, int]'
...

a: MyFunction[int] # E: "MyFunction" expects no type arguments, but 1 given
43 changes: 0 additions & 43 deletions test-data/unit/semanal-errors.test
Original file line number Diff line number Diff line change
Expand Up @@ -41,49 +41,6 @@ x = None # type: X
[out]
main:2: error: Name "X" is not defined

[case testInvalidParamSpecType1]
# flags: --python-version 3.10
from typing import ParamSpec

P = ParamSpec("P")

class MyFunction(P):
...

a: MyFunction[int]
[out]
main:6: error: Invalid location for ParamSpec "P"
main:6: note: You can use ParamSpec as the first argument to Callable, e.g., 'Callable[P, int]'
main:9: error: "MyFunction" expects no type arguments, but 1 given

[case testInvalidParamSpecType2]
from typing_extensions import ParamSpec

P = ParamSpec("P")

class MyFunction(P):
...

a: MyFunction[int]
[out]
main:5: error: Invalid location for ParamSpec "P"
main:5: note: You can use ParamSpec as the first argument to Callable, e.g., 'Callable[P, int]'
main:8: error: "MyFunction" expects no type arguments, but 1 given

[case testGenericParamSpec]
# flags: --python-version 3.10
from typing import Generic, TypeVar, Callable, ParamSpec

T = TypeVar("T")
P = ParamSpec("P")

class X(Generic[T, P]):
f: Callable[P, int]
x: T
[out]
main:7: error: Free type variable expected in Generic[...]
main:8: error: The first argument to Callable must be a list of types or "..."

[case testInvalidGenericArg]
from typing import TypeVar, Generic
t = TypeVar('t')
Expand Down