python / python/mypy

False-positive with multiple *args splats in a function call

Open
#10,481 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

mypy falsely(?) reports a type error when the *args syntax is used more than once in a function call.

To Reproduce

mypy --no-incremental --config /dev/null -c '
def foobar(a: int, b: str, c: int) -> None:
    ...


foo = (1,)
bar = ("b", 3)

foobar(*foo, *bar)
'

Expected Behavior

Success: no issues found in 1 source file

Actual Behavior

<string>:9: error: Argument 2 to "foobar" has incompatible type "*Tuple[str, int]"; expected "str"
<string>:9: error: Argument 2 to "foobar" has incompatible type "*Tuple[str, int]"; expected "int"

This error goes away if I:

  • make foo an int instead of Tuple[int], and remove the splat when foobar() is called.
  • make bar two ints and make foobar() take three int arguments.
  • make foo a Tuple[str, int] and make foobar() take str, int, str, int arguments.
  • make bar just a Tuple[str] and make foobar() take int, str arguments.

Your Environment

This occurs with the standard version of mypy in Debian Testing:

$ /usr/bin/mypy --version
mypy 0.812

...as well as with the latest git revision:

$ ~/.local/pipx/venvs/mypy/bin/mypy --version
mypy 0.820+dev.8642b351cff94c471333256f9cd6867807384f01

In both cases, I'm using the Debian-provided Python 3.9.2,
on up-to-date Debian Testing.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied mypy command and confirming the two diagnostics for the call with multiple tuple splats. Trace the call argument checking and tuple-splat handling, then add coverage for this reproducer; done means the command reports no issues without regressing the listed variations.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.