Skip to content

Conversation

@KevinRK29
Copy link
Collaborator

@KevinRK29 KevinRK29 commented Jan 16, 2026

Summary

This PR improves error messages when positional arguments are missing from a function call.

Previously when a user forgets a positional argument, mypy would previously emit multiple type errors because the subsequent arguments would be "shifted" and mismatched with their expected types. Instead of showing multiple type errors, it emits a single consolidated message that suggests which argument might be missing.

@github-actions

This comment has been minimized.

f("wrong", 123)
[builtins fixtures/primitives.pyi]
[out]
main:3: error: Incompatible arguments for "f"; check for missing arguments
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think in this case we can fall back to the pre-existing way of generating messages. It could be useful to show which types are expected vs actual, etc.

f(1, b'x', 1)
[builtins fixtures/primitives.pyi]
[out]
main:3: error: Expected "str" for parameter "y"; did you forget argument "y"?
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems inconsistent with other existing messages about argument type mismatches. Can you check these for non-overloads and see if these could be more consistent?

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

f(1, b'x', 1)
[builtins fixtures/primitives.pyi]
[out]
main:3: error: Argument 2 to "f" has incompatible type "bytes"; expected "str"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be an error about missing positional argument "y"? I think this is the only error we need to report for this call.

f("hello", b'x')
[builtins fixtures/primitives.pyi]
[out]
main:3: error: Argument 1 to "f" has incompatible type "str"; expected "int"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly, could we report missing positional argument "x", as the only error?

f("hello", b'x')
[builtins fixtures/primitives.pyi]
[out]
main:3: error: Missing positional argument "z" in call to "f"
Copy link
Collaborator

Choose a reason for hiding this comment

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

In this case it's not clear what the idea error message would be, since the caller accepts *args. One option would be to report missing positional argument x, but maybe it could result in confusing messages in other contexts, so these messages are reasonable. However, I think it would better to show the 'Missing positional argument ...' after the other messages, so that the messages could be shown in a logical order.

f("hello")
[builtins fixtures/primitives.pyi]
[out]
main:3: error: Missing positional argument "y" in call to "f"
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 report this error after the 'Argument N to ...' errors, so that we'd report the errors in the same order as the arguments are in the call.

f(1.5, [1, 2, 3])
[builtins fixtures/list.pyi]
[out]
main:3: error: Missing positional arguments "c", "d" in call to "f"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since there are multiple positional arguments missing, it seems reasonable to not try to align them, so this looks fine, but it would be clearer if the order of the errors would be different (see my other comments).

f(1, 1.5, [1, 2, 3], ("a", "b"))
[builtins fixtures/list.pyi]
[out]
main:3: error: Argument 2 to "f" has incompatible type "float"; expected "str"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, could we report missing positional argument b?

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