python / python/mypy

mypy flags "overlap between argument names and ** TypedDict items" with total=False

Open
#19,905 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-calls topic-typed-dict
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

mypy complains about explicit kwargs of a function appearing in the Unpacked TypedDict used for the ** parameter, even if the TypedDict is total=False.

To Reproduce

from typing import TypedDict, Unpack


class Opts(TypedDict, total=False):
    verbose: bool
    other: str


def do_a(*, verbose: bool = False, **_kwargs: Unpack[Opts]) -> None:
    pass


def do_b(**kwargs: Unpack[Opts]) -> None:
    pass


def do_thing(cmd: str, **kwargs: Unpack[Opts]) -> None:
    match cmd:
        case 'a':
            do_a(**kwargs)

        case 'b':
            do_b(**kwargs)

https://mypy-play.net/?mypy=latest&python=3.12&gist=a7836435f32a3fab9c3e671b73897370

Expected Behavior

I expect that this should be completely fine. Yes, verbose might end up being "stolen" away from the **kwargs in do_a() but that's quite fine, since total=False there anyway. There is no promise/expectation that verbose will be included.

Actual Behavior

main.py:9: error: Overlap between argument names and ** TypedDict items: "verbose" [misc]

Your Environment

I'm running on Fedora 42 (mypy 1.15.0 (compiled: no)), but the playground gets exactly the same error.

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 minimal reproducer in main.py, or run it in the linked mypy playground, and confirm the overlap diagnostic at line 9. Trace the mypy type-checking entry point that reports “Overlap between argument names and ** TypedDict items” for an Unpack’ed total=False TypedDict. Done means the reproducer no longer reports this error while the other typing behavior remains checked.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.