Skip to content

Type forms not allowed in any order in TypedDict functional syntax #11167

@alicederyn

Description

@alicederyn

Describe the bug
pyright is erroring if given NotRequired inside ReadOnly in the TypedDict functional syntax.

PEP-705 states that "ReadOnly[] can be used with Required[], NotRequired[] and Annotated[], in any nesting order"

Code or Screenshots

from typing import NotRequired, ReadOnly, TypedDict

# Errors with: "NotRequired" is not allowed in this context (reportInvalidTypeForm)
Foo = TypedDict("Foo", {"has-hyphens": ReadOnly[NotRequired[int]]})

playground

Switching to class-based syntax, or switching the order of ReadOnly and NotRequired, makes the error go away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions