Skip to content

No type narrowing on TypedDict values #10701

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
whtsky opened this issue Jun 23, 2021 · 2 comments
Closed

No type narrowing on TypedDict values #10701

whtsky opened this issue Jun 23, 2021 · 2 comments
Labels
bug mypy got something wrong

Comments

@whtsky
Copy link

whtsky commented Jun 23, 2021

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
@whtsky whtsky added the bug mypy got something wrong label Jun 23, 2021
@bluetech
Copy link
Contributor

Doesn't reproduce for me in master. According to git bisect, this was fixed by 8e82171 "Improve type narrowing for walrus operator in conditional statements (#11202)", which is coincidentally the current HEAD as I'm writing this :)

@hauntsaninja
Copy link
Collaborator

Thanks for checking bluetech! Going to go ahead and close this issue then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants