Skip to content

Regression with type narrowing of bool #11839

Closed
@cdce8p

Description

@cdce8p

Regression in 0.920 / 0.930 compared with 0.910.

from typing import Any

def func() -> Any:
    ...

var = func()
reveal_type(var)  # Any
assert isinstance(var, bool)
reveal_type(var)  # bool

if var:
    reveal_type(var)  # Literal[True]
    pass
reveal_type(var)  # Any -> should still be 'bool'!

The type should not be lost if it can't be narrowed to Literal[True] or Literal[False]. It's a side effect of #10389. The issue was already mentioned #10389 (comment) but hasn't been addressed yet.

/CC: @ethan-leba

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions