Skip to content

Handle prefix/suffix in typevartuple *args support #14112

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 2 commits into from
Nov 17, 2022

Conversation

jhance
Copy link
Collaborator

@jhance jhance commented Nov 16, 2022

This requires handling more cases in the various places that we previously modified to support *args in general. We also need to refresh the formals-to-actuals twice in checkexpr as now it can happen in the infer_function_type_arguments_using_context call.

The handling here is kind of asymmetric, because we can convert prefices into positional arguments, but there is no equivalent for suffices, so we represent that as a Tuple[Unpack[...], ] and handle that case separately in some spots.

We also support various edge cases like passing in a tuple without any typevartuples involved.


if len(callee_arg_types) != len(actual_types):
# TODO: Improve error message
self.chk.fail("Incorrect number of args passed", context)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update this to "Invalid number of arguments", for a little more consistent messages. It could also be good to include the name of the function being called, but that can be tweaked later.


unpacked_type = get_proper_type(var_arg.typ.type)
if isinstance(unpacked_type, TupleType):
# Assuming for now that because we convert prefices to positional arguments,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prefices -> prefixes

continue

assert len(callee_arg_types) == len(actual_types)
assert len(callee_arg_types) == len(actual_kinds)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assert seems redundant, since we check that len(actual_types) == len(actual_kinds) above.

elif isinstance(unpacked_type, TupleType):
# Prefixes get converted to positional args, so technically the only case we
# should have here is like Tuple[Unpack[Ts], Y1, Y2, Y3]. If this turns out
# not to hold we can always handle the prefices too.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prefices -> prefixes

@github-actions

This comment has been minimized.

This requires handling more cases in the various places that we
previously modified to support *args in general. We also need to refresh
the formals-to-actuals twice in checkexpr as now it can happen in the
infer_function_type_arguments_using_context call.

The handling here is kind of asymmetric, because we can convert prefices
into positional arguments, but there is no equivalent for suffices, so
we represent that as a Tuple[Unpack[...], <suffix>] and handle that case
separately in some spots.

We also support various edge cases like passing in a tuple without any
typevartuples involved.
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JukkaL JukkaL merged commit 885e361 into python:master Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants