-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
mypy/checkexpr.py
Outdated
|
||
if len(callee_arg_types) != len(actual_types): | ||
# TODO: Improve error message | ||
self.chk.fail("Incorrect number of args passed", context) |
There was a problem hiding this comment.
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.
mypy/applytype.py
Outdated
|
||
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: prefices -> prefixes
mypy/checkexpr.py
Outdated
continue | ||
|
||
assert len(callee_arg_types) == len(actual_types) | ||
assert len(callee_arg_types) == len(actual_kinds) |
There was a problem hiding this comment.
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.
mypy/constraints.py
Outdated
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: prefices -> prefixes
07bbafb
to
ab3e562
Compare
This comment has been minimized.
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.
ab3e562
to
505e0d4
Compare
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
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.