Skip to content

ParamSpecs upper bounds should be a Parameters object and not an actual object #15252

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def join_instances(self, t: Instance, s: Instance) -> ProperType:
else:
# ParamSpec type variables behave the same, independent of variance
if not is_equivalent(ta, sa):
return get_proper_type(type_var.upper_bound)
return object_from_instance(t)
new_type = join_types(ta, sa, self)
assert new_type is not None
args.append(new_type)
Expand Down
8 changes: 6 additions & 2 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4183,9 +4183,13 @@ def process_paramspec_declaration(self, s: AssignmentStmt) -> bool:
# on the lines of process_typevar_parameters

if not call.analyzed:
paramspec_var = ParamSpecExpr(
name, self.qualified_name(name), self.object_type(), INVARIANT
parameters = Parameters(
arg_types=[self.object_type(), self.object_type()],
arg_kinds=[ARG_STAR, ARG_STAR2],
arg_names=[None, None],
is_ellipsis_args=True,
)
paramspec_var = ParamSpecExpr(name, self.qualified_name(name), parameters, INVARIANT)
paramspec_var.line = call.line
call.analyzed = paramspec_var
else:
Expand Down
16 changes: 14 additions & 2 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,13 +704,14 @@ def copy_modified(
id: Bogus[TypeVarId | int] = _dummy,
flavor: int = _dummy_int,
prefix: Bogus[Parameters] = _dummy,
upper_bound: Bogus[Type] = _dummy,
) -> ParamSpecType:
return ParamSpecType(
self.name,
self.fullname,
id if id is not _dummy else self.id,
flavor if flavor != _dummy_int else self.flavor,
self.upper_bound,
upper_bound if upper_bound is not _dummy else self.upper_bound,
line=self.line,
column=self.column,
prefix=prefix if prefix is not _dummy else self.prefix,
Expand Down Expand Up @@ -1991,7 +1992,18 @@ def param_spec(self) -> ParamSpecType | None:
# TODO: confirm that all arg kinds are positional
prefix = Parameters(self.arg_types[:-2], self.arg_kinds[:-2], self.arg_names[:-2])

return arg_type.copy_modified(flavor=ParamSpecFlavor.BARE, prefix=prefix)
# TODO: should this take in `object`s? Or use prefix + *Any **Any as upper bound?
any_type = AnyType(TypeOfAny.special_form)
return arg_type.copy_modified(
flavor=ParamSpecFlavor.BARE,
prefix=prefix,
upper_bound=Parameters(
arg_types=[any_type, any_type],
arg_kinds=[ARG_STAR, ARG_STAR2],
arg_names=[None, None],
is_ellipsis_args=True,
),
)

def expand_param_spec(
self, c: CallableType | Parameters, no_prefix: bool = False
Expand Down
3 changes: 2 additions & 1 deletion test-data/unit/semanal-types.test
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,8 @@ MypyFile:1(
ImportFrom:1(typing, [ParamSpec])
AssignmentStmt:2(
NameExpr(P* [__main__.P])
ParamSpecExpr:2()))
ParamSpecExpr:2(
UpperBound(...))))

[case testTypeVarTuple]
from typing_extensions import TypeVarTuple
Expand Down