python / python/mypy

Callable with single argument accepts args expanding

Open
#13,992 2 comments 1 reaction 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

(A clear and concise description of what the bug is.)

To Reproduce

from typing import Callable, TypeVar


T_ = TypeVar("T_")
P_ = TypeVar("P_")


def convert_to_hook(f: Callable[[P_], T_]) -> Callable[[list[P_]], T_]:

    def hook_f(args: list[P_]) -> T_:
        return f(*args)

    return hook_f

https://mypy-play.net/?mypy=latest&python=3.10&gist=e45c80cbb1e609c235b4da1813501cd5

Expected Behavior

The type check should fail and point to f(*args), because f is accepting only a single argument of type P_.

Actual Behavior

Success: no issues found in 1 source file

Your Environment

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

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 reported Python reproduction and run it with the linked mypy-play example or a local mypy checkout. Trace callable and argument expansion type checking around f(*args). Done means mypy reports an error at f(*args), since f accepts only one argument of type P_.

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.