Skip to content

Accessing a NotRequired field in a TypedDict does not error #17329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mark-thm opened this issue Jun 4, 2024 · 1 comment
Closed

Accessing a NotRequired field in a TypedDict does not error #17329

mark-thm opened this issue Jun 4, 2024 · 1 comment
Labels
bug mypy got something wrong topic-typed-dict

Comments

@mark-thm
Copy link

mark-thm commented Jun 4, 2024

Bug Report

Accessing a NotRequired field in a TypedDict does not result in an error.

To Reproduce

from typing import NotRequired, TypedDict

TypeDef = TypedDict(
    "TypeDef",
    {
        "Field": NotRequired[str],
    },
)

sample = TypeDef()
val: str = sample["Field"] # expect error here

Expected Behavior

The final line should produce an error, either that "Field" is not necessarily defined or that the resulting access might produce a None, and that val is therefore the wrong type.

Actual Behavior

No error.

Your Environment

MacOS Sonoma, arm64.

  • Mypy version used: 1.10.0
  • Mypy command-line flags: default
  • Mypy configuration options from mypy.ini (and other config files): default
  • Python version used: 3.12.3
@mark-thm mark-thm added the bug mypy got something wrong label Jun 4, 2024
@AlexWaygood
Copy link
Member

Duplicate of #14717

@AlexWaygood AlexWaygood marked this as a duplicate of #14717 Jun 4, 2024
@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-typed-dict
Projects
None yet
Development

No branches or pull requests

2 participants