Skip to content

Commit

Permalink
Turn on ParamSpec semanal by default
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
hauntsaninja committed Jul 27, 2021
1 parent 524c924 commit 309f4e9
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 14 deletions.
2 changes: 2 additions & 0 deletions mypy/applytype.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def get_target_type(
skip_unsatisfied: bool
) -> Optional[Type]:
# TODO(shantanu): fix for ParamSpecDef
if not isinstance(tvar, TypeVarDef):
return None
assert isinstance(tvar, TypeVarDef)
values = get_proper_types(tvar.values)
if values:
Expand Down
2 changes: 2 additions & 0 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4481,6 +4481,8 @@ def merge_typevars_in_callables_by_name(
name = tvdef.fullname
if name not in unique_typevars:
# TODO(shantanu): fix for ParamSpecDef
if not isinstance(tvdef, TypeVarDef):
continue
assert isinstance(tvdef, TypeVarDef)
unique_typevars[name] = TypeVarType(tvdef)
variables.append(tvdef)
Expand Down
2 changes: 2 additions & 0 deletions mypy/expandtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def freshen_function_type_vars(callee: F) -> F:
tvmap: Dict[TypeVarId, Type] = {}
for v in callee.variables:
# TODO(shantanu): fix for ParamSpecDef
if not isinstance(v, TypeVarDef):
continue
assert isinstance(v, TypeVarDef)
tvdef = TypeVarDef.new_unification_variable(v)
tvdefs.append(tvdef)
Expand Down
2 changes: 0 additions & 2 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,6 @@ def add_invertible_flag(flag: str,
# Must be followed by another flag or by '--' (and then only file args may follow).
parser.add_argument('--cache-map', nargs='+', dest='special-opts:cache_map',
help=argparse.SUPPRESS)
# PEP 612 support is a work in progress, hide it from users
parser.add_argument('--wip-pep-612', action="store_true", help=argparse.SUPPRESS)

# options specifying code to check
code_group = parser.add_argument_group(
Expand Down
3 changes: 0 additions & 3 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,6 @@ def __init__(self) -> None:
# mypy. (Like mypyc.)
self.preserve_asts = False

# PEP 612 support is a work in progress, hide it from users
self.wip_pep_612 = False

# Paths of user plugins
self.plugins: List[str] = []

Expand Down
2 changes: 0 additions & 2 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3151,8 +3151,6 @@ def process_paramspec_declaration(self, s: AssignmentStmt) -> bool:
In the future, ParamSpec may accept bounds and variance arguments, in which
case more aggressive sharing of code with process_typevar_declaration should be pursued.
"""
if not self.options.wip_pep_612:
return False
call = self.get_typevarlike_declaration(
s, ("typing_extensions.ParamSpec", "typing.ParamSpec")
)
Expand Down
2 changes: 2 additions & 0 deletions mypy/typeops.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ def true_or_false(t: Type) -> ProperType:

def erase_def_to_union_or_bound(tdef: TypeVarLikeDef) -> Type:
# TODO(shantanu): fix for ParamSpecDef
if not isinstance(tdef, TypeVarDef):
return AnyType(TypeOfAny.from_error)
assert isinstance(tdef, TypeVarDef)
if tdef.values:
return make_simplified_union(tdef.values)
Expand Down
2 changes: 0 additions & 2 deletions test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
[case testBasicParamSpec]
# flags: --wip-pep-612
from typing_extensions import ParamSpec
P = ParamSpec('P')
[builtins fixtures/tuple.pyi]

[case testParamSpecLocations]
# flags: --wip-pep-612
from typing import Callable, List
from typing_extensions import ParamSpec, Concatenate
P = ParamSpec('P')
Expand Down
1 change: 0 additions & 1 deletion test-data/unit/semanal-errors.test
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,6 @@ def g() -> None:
[out]

[case testParamSpec]
# flags: --wip-pep-612
from typing_extensions import ParamSpec

TParams = ParamSpec('TParams')
Expand Down
7 changes: 3 additions & 4 deletions test-data/unit/semanal-types.test
Original file line number Diff line number Diff line change
Expand Up @@ -1500,12 +1500,11 @@ MypyFile:1(


[case testParamSpec]
# flags: --wip-pep-612
from typing import ParamSpec
P = ParamSpec("P")
[out]
MypyFile:1(
ImportFrom:2(typing, [ParamSpec])
AssignmentStmt:3(
ImportFrom:1(typing, [ParamSpec])
AssignmentStmt:2(
NameExpr(P* [__main__.P])
ParamSpecExpr:3()))
ParamSpecExpr:2()))

0 comments on commit 309f4e9

Please sign in to comment.