Skip to content

Container inference in branches #3397

@JanEricNitschke

Description

@JanEricNitschke

Describe the Bug

In a setup like

from typing import reveal_type
if input():
    x = ["a"]
    reveal_type(x)
else:
    x = []
    reveal_type(x)

reveal_type(x)

y = [] if input() else ["a"]
reveal_type(y)

pyright infers the types of both x and y as list[str], while pyrefly ends with list[str] | list[Unknown]

pyright
pyrefly

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions