Skip to content

No type narrowing on TypedDict values #10701

Closed
@whtsky

Description

@whtsky

Bug Report

a.py:

from typing import Optional
from typing import TypedDict

class D(TypedDict):
    a: int


v: Optional[D]

v and v['a']

class P(TypedDict):
    v: Optional[D]

p: P
p['v'] and p['v']['a']

To Reproduce

mypy a.py

Expected Behavior

No error report

Actual Behavior

a.py:16: error: Value of type "Optional[D]" is not indexable
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: no flags
  • Mypy configuration options from mypy.ini (and other config files): no config file
  • Python version used: Python 3.9.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions