Skip to content

Distinguish "after successful call" disjointness of callables #3619

@carljm

Description

@carljm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type propertiessubtyping, assignability, equivalence, and moreunsoundnessTy can give an expression type T, but at runtime it can have a non-T value, with no diagnostic.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions