python / python/mypy

Passing `**dict(...)` to `functools.partial` confuses mypy

Open
#18,644 0 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

Something like partial(func, **dict(a=1)) confuses mypy which seems to expect the dictionary keys to contain all the arguments to func, leading to errors if positional arguments are not specified (see this playground / gist), or if only a few arguments are specified and later more as passed to partial's return value (see this playground / gist).

Expected Behavior

I realise that mypy cannot know what ends up in an untyped dictionary, but it should maybe just give up in this case.

Actual Behavior

See gist.

Your Environment

  • Mypy version used: mypy 1.15.0 (compiled: yes), but also master while using the playground
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10.1, but also 3.13 while using the playground

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 reproducing the two examples in the linked mypy playgrounds and gists with mypy 1.15.0 and master. Trace how functools.partial handles unpacked dictionaries, then verify that the reported cases no longer produce erroneous diagnostics while valid partial calls remain checked.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.