python / python/mypy

MyPy yield a false error with function(*args, x)

Open
#16,677 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 wrongly produce an error for "Too many argument" when calling a function with star syntax followed by an additional argument.

To Reproduce


def foo(a: int, b: int, c: int, d: int) -> None:
    return None

lst = [1, 2, 3]
foo(*lst, 4)

Expected Behavior
MyPy should not yield any error, and the types are fit.

Actual Behavior
An error occurs:

mypy_reproduce.py:6: error: Too many arguments for "foo"  [call-arg]

Your Environment

  • Mypy version used:1.4.1
  • Mypy command-line flags: No flags
  • Mypy configuration options from mypy.ini (and other config files): No config
  • Python version used: 3.7.3

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 with the provided Python reproducer and inspect mypy's argument-checking path for calls combining starred arguments with a following positional argument. Compare the reported result with the expected acceptance of foo(*lst, 4), and verify that the false "Too many arguments" error is no longer produced.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.