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

TypedDict:__required_keys__ and__optional_keys__ can be wrong in the presence of inheritance #112509

Closed
Labels
3.11only security fixes3.12only security fixes3.13bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error
@JelleZijlstra

Description

@JelleZijlstra

Bug report

Bug description:

fromtypingimportNotRequired,Required,TypedDictclassA(TypedDict):a:NotRequired[int]b:Required[int]classB(A):a:Required[int]b:NotRequired[int]print(B.__required_keys__)print(B.__optional_keys__)

This will print (tried on 3.11 and current-ish main):

frozenset({'b', 'a'})frozenset({'b', 'a'})

But obviously, a single key should only be either Required or NotRequired, not both. The child class's version should prevail.

@alicederyn and I discovered this while discussing the implementation ofPEP-705 (python/typing_extensions#284). cc@davidfstr for PEP 655.

I also see some problems with how type checkers handle this case, but i'll post about that separately.

CPython versions tested on:

3.11, CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp