Skip to content

False negative: popping a ReadOnly key from a TypedDict #19130

Closed
@JelleZijlstra

Description

@JelleZijlstra

Mypy reports no error for this program:

from typing import ReadOnly, TypedDict, NotRequired

class TD(TypedDict):
    x: ReadOnly[NotRequired[int]]
    
def f(td: TD):
    td.pop("x")

https://mypy-play.net/?mypy=latest&python=3.13&gist=9dfad53c9dc2e22c63548a553afdb67e

But deleting a ReadOnly key should not be allowed. The spec says:

The typing.ReadOnly type qualifier is used to indicate that an item declared in a TypedDict definition may not be mutated (added, modified, or removed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions