pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

Refinement should not turn static types into gradual types

Open grievejia opened this issue 10 months ago • 1 comments

Describe the Bug

Minimal repro:

def _(flag: bool, t: type) -> None:
    x = 1 if flag else "foo"

    if isinstance(x, t):
        reveal_type(x)

Expected: reveals Literal[1, "foo"] Actual: reveals Unknown

Sandbox Link

https://pyrefly.org/sandbox/?code=CYUwZgBA+gFGA2BDA5gLggIwPZfgGggBd1CBPABxAEoIBaAPggDksA7EVAKAh4gA8IAXggBGCAEtICFBBDwAziAgAiMDmWduvSRPnjW8wolYBjEDD4FCVLrzsQATiABuIRPChlKFqkA

(Only applicable for extension issues) IDE Information

No response

grievejia avatar May 18 '25 17:05 grievejia

the underlying issue seems to be treating Any as both the subtype and the supertype of every type. note e.g. that if you reverse the order of the first two branches here this test passes and some other tests start failing.

perhaps special-casing Any within isinstance is enough here - i don't think the issue will arise for types other than Any

martindemello avatar May 22 '25 02:05 martindemello