facebook / pyre-check

Performant type-checking for python.
https://pyre-check.org/
MIT License
6.86k stars 437 forks source link

Pyre cannot narrow literal types #911

Closed vthemelis closed 1 month ago

vthemelis commented 3 months ago

Pyre Bug

Bug description

Pyre cannot reason about narrowing of literal types:

from typing import Literal, assert_never

def foo(x: Literal["a", "b"]) -> str:
    if x == "a":
        return "a"
    if x == "b":
        return "b"
    else:
        assert_never(x)

This should obviously type check (and it does for pyright)

See Pyre playground

yangdanny97 commented 1 month ago

Thanks for reporting! This has been fixed in https://github.com/facebook/pyre-check/commit/58b242612f8e0e2f27c8ca40729b011d7e3edd26 and should be available in the next release.