astral-sh/ruff#25315 implemented disjointness of a protocol method from a type with that method, if the methods return disjoint types. It's noted on this PR that this is technically not sound due to the possibility of a common subtype method returning Never.
One way to thread this needle soundly would be to consider a distinct category of "callables which have been called with a successful return". For example, if we generate a synthetic protocol from narrowing that occurs based on a __len__ check, we know that __len__ did not diverge, so we can safely discard the possibility that it returns Never. We could mark these synthetic protocols in a way that allows us to use this logic when determining disjointness of their methods, but not apply that logic in general, even for other protocol types.
astral-sh/ruff#25315 implemented disjointness of a protocol method from a type with that method, if the methods return disjoint types. It's noted on this PR that this is technically not sound due to the possibility of a common subtype method returning
Never.One way to thread this needle soundly would be to consider a distinct category of "callables which have been called with a successful return". For example, if we generate a synthetic protocol from narrowing that occurs based on a
__len__check, we know that__len__did not diverge, so we can safely discard the possibility that it returnsNever. We could mark these synthetic protocols in a way that allows us to use this logic when determining disjointness of their methods, but not apply that logic in general, even for other protocol types.