Skip to content

emit diagnostic on access of NotRequired typeddict key #2810

@GniLudio

Description

@GniLudio

Summary

Even though the feature overview and the support TypedDict issues show NotRequired as supported, it seems to be not working correctly.

In the following example MyDict.foo must not necessarily exist, but ty always assumes it's existence.

Example

from typing import TypedDict, NotRequired

class MyDict(TypedDict):
    foo: NotRequired[str]

my_dict: MyDict = {}

# assignment to a string variable doesn't give a warning
my_string: str = my_dict["foo"]

# assignment to a string parameter doesn't give a warning
def print_string(s: str) -> None:
    print(s)
print_string(my_dict["foo"])

Playground

Version

ty 0.0.17 (8cec857 2026-02-13)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions