Skip to content

narrowing union of lists by type of an item in the list doesn't work #11436

Description

@DetachHead
def foo() -> list[int] | list[None]:
    ...


bar = foo()

if bar[0] is not None:
    reveal_type(bar) # Revealed type is "Union[builtins.list[builtins.int], builtins.list[None]]

https://mypy-play.net/?mypy=latest&python=3.10&gist=f705728f126594fe4d4912e3707b9121

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-type-narrowingConditional type narrowing / binder

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions