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
Thanks for the clarification! I see the issue now. The sorted() function was allowing tuples containing non-comparable types to be sorted, which caused the TypeError at runtime.
This is a problem with the SupportsRichComparison protocol in general, it's difficult to frame comparability purely as a type, so I don't think it will be possible to get rid of this false negative without type inversion.
You'd need something like this recursive type definition with type intersection and type inversion to handle this case properly
type Comparable= (SupportsRichComparison&Not[tuple[Any, ...]) |tuple[Comparable, ...]
sorted()
does not enforce that every item in the tuple must be comparable:typeshed/stdlib/builtins.pyi
Lines 1762 to 1767 in e5c5318
The text was updated successfully, but these errors were encountered: