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
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

spark (https://github.com/apache/spark)
+ python/pyspark/streaming/dstream.py:236: error: Unused "type: ignore[arg-type]" comment  [unused-ignore]
+ python/pyspark/streaming/dstream.py:410: error: Unused "type: ignore[arg-type]" comment  [unused-ignore]
+ python/pyspark/streaming/dstream.py:453: error: Unused "type: ignore[arg-type]" comment  [unused-ignore]

prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/cli/work_pool.py:206: error: Incompatible arguments for "provision"; check for missing arguments  [call-arg]
- src/prefect/cli/work_pool.py:206: error: Missing positional argument "self" in call to "provision" of "Provisioner"  [call-arg]
- src/prefect/cli/work_pool.py:207: error: Argument "base_job_template" to "provision" of "Provisioner" has incompatible type "dict[str, Any] | None"; expected "dict[str, Any]"  [arg-type]

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+ tests/annotations/mypy_checks.py:86: error: Unused "type: ignore[arg-type]" comment  [unused-ignore]

ibis (https://github.com/ibis-project/ibis)
- ibis/expr/datatypes/core.py:304: error: Too few arguments for "Array"  [call-arg]
+ ibis/expr/datatypes/core.py:304: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/expr/datatypes/core.py:304: error: Argument 1 to "Array" has incompatible type "Int64"; expected "bool"  [arg-type]
- ibis/expr/datatypes/core.py:307: error: Too few arguments for "Map"  [call-arg]
+ ibis/expr/datatypes/core.py:307: error: Incompatible arguments for "Map"; check for missing arguments  [call-arg]
- ibis/expr/datatypes/core.py:307: error: Argument 1 to "Map" has incompatible type "Int64"; expected "bool"  [arg-type]
- ibis/expr/datatypes/core.py:968: error: "Struct" gets multiple values for keyword argument "nullable"  [misc]
- ibis/expr/datatypes/core.py:968: error: Too few arguments for "Struct"  [call-arg]
+ ibis/expr/datatypes/core.py:968: error: Incompatible arguments for "Struct"; check for missing arguments  [call-arg]
- ibis/expr/datatypes/core.py:968: error: Argument 1 to "Struct" has incompatible type "dict[str, str | DataType]"; expected "bool"  [arg-type]
- ibis/expr/datatypes/value.py:48: error: Too few arguments for "Struct"  [call-arg]
+ ibis/expr/datatypes/value.py:48: error: Incompatible arguments for "Struct"; check for missing arguments  [call-arg]
- ibis/expr/datatypes/value.py:48: error: Argument 1 to "Struct" has incompatible type "dict[str, Any]"; expected "bool"  [arg-type]
- ibis/expr/datatypes/value.py:55: error: Too few arguments for "Map"  [call-arg]
+ ibis/expr/datatypes/value.py:55: error: Incompatible arguments for "Map"; check for missing arguments  [call-arg]
- ibis/expr/datatypes/value.py:55: error: Argument 1 to "Map" has incompatible type "Null"; expected "bool"  [arg-type]
- ibis/expr/datatypes/value.py:69: error: Too few arguments for "Array"  [call-arg]
+ ibis/expr/datatypes/value.py:69: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/expr/datatypes/value.py:69: error: Argument 1 to "Array" has incompatible type "Null"; expected "bool"  [arg-type]
- ibis/expr/datatypes/value.py:101: error: Too few arguments for "Interval"  [call-arg]
+ ibis/expr/datatypes/value.py:101: error: Incompatible arguments for "Interval"; check for missing arguments  [call-arg]
- ibis/expr/datatypes/value.py:101: error: Argument 1 to "Interval" has incompatible type "IntervalUnit"; expected "bool"  [arg-type]
- ibis/expr/datatypes/value.py:104: error: Too few arguments for "Interval"  [call-arg]
+ ibis/expr/datatypes/value.py:104: error: Incompatible arguments for "Interval"; check for missing arguments  [call-arg]
- ibis/expr/datatypes/value.py:104: error: Argument 1 to "Interval" has incompatible type "IntervalUnit"; expected "bool"  [arg-type]
- ibis/expr/datatypes/value.py:106: error: Too few arguments for "Interval"  [call-arg]
+ ibis/expr/datatypes/value.py:106: error: Incompatible arguments for "Interval"; check for missing arguments  [call-arg]
- ibis/expr/datatypes/value.py:106: error: Argument 1 to "Interval" has incompatible type "IntervalUnit"; expected "bool"  [arg-type]
- ibis/expr/datatypes/value.py:108: error: Too few arguments for "Interval"  [call-arg]
+ ibis/expr/datatypes/value.py:108: error: Incompatible arguments for "Interval"; check for missing arguments  [call-arg]
- ibis/expr/datatypes/value.py:108: error: Argument 1 to "Interval" has incompatible type "IntervalUnit"; expected "bool"  [arg-type]
- ibis/expr/datatypes/value.py:205: error: Too few arguments for "Interval"  [call-arg]
+ ibis/expr/datatypes/value.py:205: error: Incompatible arguments for "Interval"; check for missing arguments  [call-arg]
- ibis/expr/datatypes/value.py:205: error: Argument 1 to "Interval" has incompatible type "str"; expected "bool"  [arg-type]
- ibis/expr/schema.py:306: error: Too few arguments for "Struct"  [call-arg]
+ ibis/expr/schema.py:306: error: Incompatible arguments for "Struct"; check for missing arguments  [call-arg]
- ibis/expr/schema.py:306: error: Argument 1 to "Struct" has incompatible type "Schema"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:208: error: "Array" gets multiple values for keyword argument "nullable"  [misc]
- ibis/backends/sql/datatypes.py:208: error: Too few arguments for "Array"  [call-arg]
+ ibis/backends/sql/datatypes.py:208: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:209: error: Argument 1 to "Array" has incompatible type "DataType"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:211: error: Argument "nullable" to "Array" has incompatible type "bool | None"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:254: error: "Map" gets multiple values for keyword argument "nullable"  [misc]
- ibis/backends/sql/datatypes.py:254: error: Too few arguments for "Map"  [call-arg]
+ ibis/backends/sql/datatypes.py:254: error: Incompatible arguments for "Map"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:254: error: Argument 1 to "Map" has incompatible type "DataType"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:254: error: Argument "nullable" to "Map" has incompatible type "bool | None"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:272: error: "Struct" gets multiple values for keyword argument "nullable"  [misc]
- ibis/backends/sql/datatypes.py:272: error: Too few arguments for "Struct"  [call-arg]
+ ibis/backends/sql/datatypes.py:272: error: Incompatible arguments for "Struct"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:272: error: Argument 1 to "Struct" has incompatible type "dict[Any, DataType]"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:272: error: Argument "nullable" to "Struct" has incompatible type "bool | None"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:319: error: "Interval" gets multiple values for keyword argument "nullable"  [misc]
- ibis/backends/sql/datatypes.py:319: error: Too few arguments for "Interval"  [call-arg]
+ ibis/backends/sql/datatypes.py:319: error: Incompatible arguments for "Interval"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:319: error: Argument 1 to "Interval" has incompatible type "str"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:319: error: Argument "nullable" to "Interval" has incompatible type "bool | None"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:514: error: Too few arguments for "Array"  [call-arg]
+ ibis/backends/sql/datatypes.py:514: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:514: error: Argument 1 to "Array" has incompatible type "LineString"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:516: error: Too few arguments for "Array"  [call-arg]
+ ibis/backends/sql/datatypes.py:516: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:516: error: Argument 1 to "Array" has incompatible type "Polygon"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:518: error: Too few arguments for "Array"  [call-arg]
+ ibis/backends/sql/datatypes.py:518: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:518: error: Argument 1 to "Array" has incompatible type "Point"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:520: error: Too few arguments for "Array"  [call-arg]
+ ibis/backends/sql/datatypes.py:520: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:520: error: Argument 1 to "Array" has incompatible type "MACADDR"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:522: error: Too few arguments for "Array"  [call-arg]
+ ibis/backends/sql/datatypes.py:522: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:522: error: Argument 1 to "Array" has incompatible type "MACADDR"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:711: error: Too few arguments for "Interval"  [call-arg]
+ ibis/backends/sql/datatypes.py:711: error: Incompatible arguments for "Interval"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:711: error: Argument 1 to "Interval" has incompatible type "str"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:712: error: Too few arguments for "Interval"  [call-arg]
+ ibis/backends/sql/datatypes.py:712: error: Incompatible arguments for "Interval"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:712: error: Argument 1 to "Interval" has incompatible type "str"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:865: error: "Array" gets multiple values for keyword argument "nullable"  [misc]
- ibis/backends/sql/datatypes.py:865: error: Too few arguments for "Array"  [call-arg]
+ ibis/backends/sql/datatypes.py:865: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:865: error: Argument 1 to "Array" has incompatible type "JSON"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:865: error: Argument "nullable" to "Array" has incompatible type "bool | None"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:1252: error: "Array" gets multiple values for keyword argument "nullable"  [misc]
- ibis/backends/sql/datatypes.py:1252: error: Too few arguments for "Array"  [call-arg]
+ ibis/backends/sql/datatypes.py:1252: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:1252: error: Argument 1 to "Array" has incompatible type "Null"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:1253: error: "Array" gets multiple values for keyword argument "nullable"  [misc]
- ibis/backends/sql/datatypes.py:1253: error: Too few arguments for "Array"  [call-arg]
+ ibis/backends/sql/datatypes.py:1253: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:1253: error: Argument 1 to "Array" has incompatible type "Null"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:1317: error: "Array" gets multiple values for keyword argument "nullable"  [misc]
- ibis/backends/sql/datatypes.py:1317: error: Too few arguments for "Array"  [call-arg]
+ ibis/backends/sql/datatypes.py:1317: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:1317: error: Argument 1 to "Array" has incompatible type "DataType"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:1317: error: Argument "nullable" to "Array" has incompatible type "bool | None"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:1320: error: "Struct" gets multiple values for keyword argument "nullable"  [misc]
- ibis/backends/sql/datatypes.py:1320: error: Too few arguments for "Struct"  [call-arg]
+ ibis/backends/sql/datatypes.py:1320: error: Incompatible arguments for "Struct"; check for missing arguments  [call-arg]
- ibis/backends/sql/datatypes.py:1320: error: Argument 1 to "Struct" has incompatible type "tuple[Any, ...]"; expected "bool"  [arg-type]
- ibis/backends/sql/datatypes.py:1320: error: Argument "nullable" to "Struct" has incompatible type "bool | None"; expected "bool"  [arg-type]
- ibis/formats/pyarrow.py:95: error: "Array" gets multiple values for keyword argument "nullable"  [misc]
- ibis/formats/pyarrow.py:95: error: Too few arguments for "Array"  [call-arg]
+ ibis/formats/pyarrow.py:95: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/formats/pyarrow.py:95: error: Argument 1 to "Array" has incompatible type "DataType"; expected "bool"  [arg-type]
- ibis/formats/pyarrow.py:98: error: "Array" gets multiple values for keyword argument "nullable"  [misc]
- ibis/formats/pyarrow.py:98: error: Too few arguments for "Array"  [call-arg]
+ ibis/formats/pyarrow.py:98: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/formats/pyarrow.py:98: error: Argument 1 to "Array" has incompatible type "DataType"; expected "bool"  [arg-type]
- ibis/formats/pyarrow.py:103: error: "Struct" gets multiple values for keyword argument "nullable"  [misc]
- ibis/formats/pyarrow.py:103: error: Too few arguments for "Struct"  [call-arg]
+ ibis/formats/pyarrow.py:103: error: Incompatible arguments for "Struct"; check for missing arguments  [call-arg]
- ibis/formats/pyarrow.py:103: error: Argument 1 to "Struct" has incompatible type "dict[Any, DataType]"; expected "bool"  [arg-type]
- ibis/formats/pyarrow.py:108: error: "Map" gets multiple values for keyword argument "nullable"  [misc]
- ibis/formats/pyarrow.py:108: error: Too few arguments for "Map"  [call-arg]
+ ibis/formats/pyarrow.py:108: error: Incompatible arguments for "Map"; check for missing arguments  [call-arg]
- ibis/formats/pyarrow.py:108: error: Argument 1 to "Map" has incompatible type "DataType"; expected "bool"  [arg-type]
- ibis/formats/polars.py:70: error: "Array" gets multiple values for keyword argument "nullable"  [misc]
- ibis/formats/polars.py:70: error: Too few arguments for "Array"  [call-arg]
+ ibis/formats/polars.py:70: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/formats/polars.py:70: error: Argument 1 to "Array" has incompatible type "DataType"; expected "bool"  [arg-type]
- ibis/formats/numpy.py:54: error: "Interval" gets multiple values for keyword argument "nullable"  [misc]
- ibis/formats/numpy.py:54: error: Too few arguments for "Interval"  [call-arg]
+ ibis/formats/numpy.py:54: error: Incompatible arguments for "Interval"; check for missing arguments  [call-arg]
- ibis/formats/numpy.py:54: error: Argument 1 to "Interval" has incompatible type "str"; expected "bool"  [arg-type]
- ibis/expr/operations/strings.py:267: error: Too few arguments for "Array"  [call-arg]
+ ibis/expr/operations/strings.py:267: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/expr/operations/strings.py:267: error: Argument 1 to "Array" has incompatible type "String"; expected "bool"  [arg-type]
- ibis/expr/operations/strings.py:302: error: Too few arguments for "Array"  [call-arg]
+ ibis/expr/operations/strings.py:302: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/expr/operations/strings.py:302: error: Argument 1 to "Array" has incompatible type "String"; expected "bool"  [arg-type]
- ibis/expr/operations/temporal.py:308: error: Too few arguments for "Interval"  [call-arg]
+ ibis/expr/operations/temporal.py:308: error: Incompatible arguments for "Interval"; check for missing arguments  [call-arg]
- ibis/expr/operations/temporal.py:308: error: Argument 1 to "Interval" has incompatible type "str"; expected "bool"  [arg-type]
- ibis/expr/operations/temporal.py:338: error: Too few arguments for "Interval"  [call-arg]
+ ibis/expr/operations/temporal.py:338: error: Incompatible arguments for "Interval"; check for missing arguments  [call-arg]
- ibis/expr/operations/temporal.py:338: error: Argument 1 to "Interval" has incompatible type "str"; expected "bool"  [arg-type]
- ibis/expr/operations/temporal.py:368: error: Too few arguments for "Interval"  [call-arg]
+ ibis/expr/operations/temporal.py:368: error: Incompatible arguments for "Interval"; check for missing arguments  [call-arg]
- ibis/expr/operations/temporal.py:368: error: Argument 1 to "Interval" has incompatible type "str"; expected "bool"  [arg-type]
- ibis/expr/operations/json.py:34: error: Too few arguments for "Array"  [call-arg]
+ ibis/expr/operations/json.py:34: error: Incompatible arguments for "Array"; check for missing arguments  [call-arg]
- ibis/expr/operations/json.py:34: error: Argument 1 to "Array" has incompatible type "JSON"; expected "bool"  [arg-type]
- ibis/expr/operations/json.py:47: error: Too few arguments for "Map"  [call-arg]
+ ibis/expr/operations/json.py:47: error: Incompatible arguments for "Map"; check for missing arguments  [call-arg]
- ibis/expr/operations/json.py:47: error: Argument 1 to "Map" has incompatible type "String"; expected "bool"  [arg-type]
+ ibis/expr/types/generic.py:1284: error: Incompatible arguments for "GroupConcat"; check for missing arguments  [call-arg]

... (truncated 772 lines) ...

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?

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