Skip to content

Conversation

@KevinRK29
Copy link
Collaborator

Summary

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

Problem

When a user forgets a positional argument, mypy would previously emit multiple confusing type errors because the subsequent arguments would be "shifted" and mismatched with their expected types.

Solution

Detect patterns where a forgotten positional argument causes subsequent arguments to be misaligned with their expected parameters. Instead of showing multiple type errors, emit 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
Copy link
Contributor

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

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