Skip to content

TypedDict with extra_items breaks control flow analyis of in operator #11438

@moosbruggerj

Description

@moosbruggerj

Describe the bug
When checking the existence of a key in a TypedDict which has extra_items defined, the unreachability analysis seems to assume every key is present.
Testing a normally defined key in the same dict behaves as expected.

Code or Screenshots

In the code below, pyright claims the print statement is never reached.

from typing import TypedDict

class Typed(TypedDict, extra_items=str):
    a: str

def test(d: Typed) -> None:
    if "b" in d:
        return
    print("here")

https://pyright-play.net/?strict=true&code=GYJw9gtgBALgngBwJYDsDmUkQWEMoAqiApgCYAiSAxjAFC1UA2AhgM6uEmkAURCZlGgBooxAB4wQzAPpIYxCKwC8rSQEoAXLSg6ozDVFUh6pYsFjFV3Ugb5k1UALQA%2BKADkwKYlt2ZzAIgAjf0wUKBttX10QYhgAVxAUSJ0EEFQYbn8AC2IY-zVaIA

VS Code extension or command-line
pyright 1.1409

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