You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pyrefly and Pyright treat conformance for overload matching differently. #5239
I believe the type spec says the typechecker has to not show an error when accessing any of the possible values for the returned value.
Pyrefly handles this by just marking all ambiguous matches as Any.
Pyright was handling this by just picking the first match (which is not conformant because it shows errors for the other matches) but is in the process of representing the result as a kind of intersection of list[int] and list[str].
Looks like this was added to the conformance test from this post. Pyright still seems to fail because it errors here:
def check_example5(b: list[Any]) -> None:
ret = example5(b)
int_list: list[int] = ret # must not error
str_list: list[str] = ret # must not error
I don't have strong opinions on what Pyrefly should do here yet (or thoughts on how) but it does seem like an improvement in this case to create List[Any] over Any.
I've been playing around with another idea, which is to use pyrefly's existing Type::Overloaded construct (which behaves like an ordered "any of" type) to represent these ambiguous cases, so in the example above, we'd emit Overloaded[list[int], list[str]], which would be usable anywhere either list[int] or list[str] is. (Pyright's "a kind of intersection of list[int] and list[str]" sounds like it may be a similar idea?) The problem that I've gotten a little stuck on is that Overloaded was introduced for a far more limited use case, and adopting it for overload evaluation would mean it appears in a lot more places that don't currently expect or handle Overloaded.
Activity
rchiodo commentedon Oct 14, 2026
I believe Ty returns 'Any' in this case
kinto0 commentedon Oct 14, 2026
Looks like this was added to the conformance test from this post. Pyright still seems to fail because it errors here:
I don't have strong opinions on what Pyrefly should do here yet (or thoughts on how) but it does seem like an improvement in this case to create
List[Any]overAny.rchiodo commentedon Oct 14, 2026
Yeah I'm fixing the second case right now in microsoft/pyright#11864.
rchen152 commentedon Oct 16, 2026
Related: #4910.
I've been playing around with another idea, which is to use pyrefly's existing
Type::Overloadedconstruct (which behaves like an ordered "any of" type) to represent these ambiguous cases, so in the example above, we'd emitOverloaded[list[int], list[str]], which would be usable anywhere eitherlist[int]orlist[str]is. (Pyright's "a kind of intersection of list[int] and list[str]" sounds like it may be a similar idea?) The problem that I've gotten a little stuck on is thatOverloadedwas introduced for a far more limited use case, and adopting it for overload evaluation would mean it appears in a lot more places that don't currently expect or handleOverloaded.rchen152 commentedon Nov 5, 2026
Actually, I'm going to dedup this issue into the other one, since I think they'll need the same solution.
Unknown#4910