Skip to content

Commit 309f4e9

Browse files
author
hauntsaninja
committed
Turn on ParamSpec semanal by default
This PR does not mean mypy supports PEP 612, but it does do enough to unblock python#10862 mypy should now treat Callable[P, T] as Callable[..., T] and the code paths with incomplete support will no longer crash (but will not do what you'd want)
1 parent 524c924 commit 309f4e9

File tree

10 files changed

+11
-14
lines changed

10 files changed

+11
-14
lines changed

mypy/applytype.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def get_target_type(
1919
skip_unsatisfied: bool
2020
) -> Optional[Type]:
2121
# TODO(shantanu): fix for ParamSpecDef
22+
if not isinstance(tvar, TypeVarDef):
23+
return None
2224
assert isinstance(tvar, TypeVarDef)
2325
values = get_proper_types(tvar.values)
2426
if values:

mypy/checkexpr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4481,6 +4481,8 @@ def merge_typevars_in_callables_by_name(
44814481
name = tvdef.fullname
44824482
if name not in unique_typevars:
44834483
# TODO(shantanu): fix for ParamSpecDef
4484+
if not isinstance(tvdef, TypeVarDef):
4485+
continue
44844486
assert isinstance(tvdef, TypeVarDef)
44854487
unique_typevars[name] = TypeVarType(tvdef)
44864488
variables.append(tvdef)

mypy/expandtype.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def freshen_function_type_vars(callee: F) -> F:
4141
tvmap: Dict[TypeVarId, Type] = {}
4242
for v in callee.variables:
4343
# TODO(shantanu): fix for ParamSpecDef
44+
if not isinstance(v, TypeVarDef):
45+
continue
4446
assert isinstance(v, TypeVarDef)
4547
tvdef = TypeVarDef.new_unification_variable(v)
4648
tvdefs.append(tvdef)

mypy/main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,6 @@ def add_invertible_flag(flag: str,
852852
# Must be followed by another flag or by '--' (and then only file args may follow).
853853
parser.add_argument('--cache-map', nargs='+', dest='special-opts:cache_map',
854854
help=argparse.SUPPRESS)
855-
# PEP 612 support is a work in progress, hide it from users
856-
parser.add_argument('--wip-pep-612', action="store_true", help=argparse.SUPPRESS)
857855

858856
# options specifying code to check
859857
code_group = parser.add_argument_group(

mypy/options.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,6 @@ def __init__(self) -> None:
242242
# mypy. (Like mypyc.)
243243
self.preserve_asts = False
244244

245-
# PEP 612 support is a work in progress, hide it from users
246-
self.wip_pep_612 = False
247-
248245
# Paths of user plugins
249246
self.plugins: List[str] = []
250247

mypy/semanal.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,8 +3151,6 @@ def process_paramspec_declaration(self, s: AssignmentStmt) -> bool:
31513151
In the future, ParamSpec may accept bounds and variance arguments, in which
31523152
case more aggressive sharing of code with process_typevar_declaration should be pursued.
31533153
"""
3154-
if not self.options.wip_pep_612:
3155-
return False
31563154
call = self.get_typevarlike_declaration(
31573155
s, ("typing_extensions.ParamSpec", "typing.ParamSpec")
31583156
)

mypy/typeops.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ def true_or_false(t: Type) -> ProperType:
512512

513513
def erase_def_to_union_or_bound(tdef: TypeVarLikeDef) -> Type:
514514
# TODO(shantanu): fix for ParamSpecDef
515+
if not isinstance(tdef, TypeVarDef):
516+
return AnyType(TypeOfAny.from_error)
515517
assert isinstance(tdef, TypeVarDef)
516518
if tdef.values:
517519
return make_simplified_union(tdef.values)

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
[case testBasicParamSpec]
2-
# flags: --wip-pep-612
32
from typing_extensions import ParamSpec
43
P = ParamSpec('P')
54
[builtins fixtures/tuple.pyi]
65

76
[case testParamSpecLocations]
8-
# flags: --wip-pep-612
97
from typing import Callable, List
108
from typing_extensions import ParamSpec, Concatenate
119
P = ParamSpec('P')

test-data/unit/semanal-errors.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,6 @@ def g() -> None:
14261426
[out]
14271427

14281428
[case testParamSpec]
1429-
# flags: --wip-pep-612
14301429
from typing_extensions import ParamSpec
14311430

14321431
TParams = ParamSpec('TParams')

test-data/unit/semanal-types.test

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,12 +1500,11 @@ MypyFile:1(
15001500

15011501

15021502
[case testParamSpec]
1503-
# flags: --wip-pep-612
15041503
from typing import ParamSpec
15051504
P = ParamSpec("P")
15061505
[out]
15071506
MypyFile:1(
1508-
ImportFrom:2(typing, [ParamSpec])
1509-
AssignmentStmt:3(
1507+
ImportFrom:1(typing, [ParamSpec])
1508+
AssignmentStmt:2(
15101509
NameExpr(P* [__main__.P])
1511-
ParamSpecExpr:3()))
1510+
ParamSpecExpr:2()))

0 commit comments

Comments
 (0)