Skip to content

final TypedDict with total=False does not allow clear/popitem #14914

Open
@alicederyn

Description

@alicederyn

Bug Report

PEP-589 disallows clear and popitem on TypedDicts, even if all known keys are not required, as there may be other required keys due to structural subtyping. However, a @final-decorated TypedDict cannot be structurally subtyped, so these methods should be available.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.11&gist=7d42af8206cb1e25a53673bdf4e99df1

from typing import TypedDict, final

@final
class A(TypedDict, total=False):
    k: int

a: A = {"k": 1}
a.clear()

Expected Behavior

No errors

Actual Behavior

error: "A" has no attribute "clear"  [attr-defined]

Your Environment

  • Mypy version used: 1.0.0
  • Python version used: 3.11

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions