Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Dict unpacking fails when used for building TypedDict with required keys #19467

Open
Labels
@adamantike

Description

@adamantike

Bug Report

When dict unpacking is used to dynamically add optional keys to a TypedDict,mypy raises atypeddict-item error.
As dict unpacking is used to fill some keys from the TypedDict, my understanding is thatmypy could validate the unpacked dictionaries considering all keys asNotRequired, and only the final TypedDict respecting its formal definition.

To Reproduce

Gist:https://mypy-play.net/?mypy=latest&python=3.13&gist=b3377281f7f5a6f83dd9962d60302827

fromtypingimportNotRequired,TypedDictclassProject(TypedDict):name:strversion:NotRequired[str]defbuild_project(name:str,version:str|None=None)->Project:return {"name":name,**({"version":version}ifversionisnotNoneelse {})    }

Actual Behavior

$ mypy .main.py:12: error: Missing key "name" for TypedDict "Project"  [typeddict-item]Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used:1.17.0
  • Mypy command-line flags: N/A
  • Mypy configuration options frommypy.ini (and other config files): N/A
  • Python version used:3.13.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp