Skip to content

ReadOnly field can be added when subclassing a TypedDict with mutable extra_items #11037

Closed

Description

@ZhaJiMan
from typing_extensions import TypedDict, NotRequired, ReadOnly


class A(TypedDict, extra_items=float):
    x: float
    y: float


class B(A):
    z: ReadOnly[NotRequired[float]]


def f(a: A) -> None:
    a["z"] = 0


b: B = {"x": 1, "y": 2, "z": 3}
f(b)

pyright playground version

Class A has mutable extra_items, while its subclass B adds a new read-only field. However, this field can be mutated by functions that accept type A, which violates the ReadOnly constraint. Why do pyright allow this?

Activity

  1. added
    bug
    on Oct 16, 2025
  2. added
    addressed in next version
    on Oct 16, 2025
  3. erictraut commented on Oct 22, 2025

    @erictraut
    Collaborator

    This is addressed in pyright 1.1.407

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions