pyrefly
pyrefly copied to clipboard
Refinement should not turn static types into gradual types
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
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