Skip to content

Improve type inference for recursive protocols #3829

Open
@ilevkivskyi

Description

@ilevkivskyi

Consider this example:

class P(Protocol[T_co]):
    def meth(self) -> P[T_co]: ...

class C(Generic[T]):
    def meth(self) -> C[T]: ...

def fun(arg: P[T]) -> T: ...
x: C[int]
reveal_type(f(x))  # I think this should be 'int'

But currently the inferred type is UninhabitedType, since we don't find any constraints for T due to a purely structural inference cycle. Unfortunately, it looks like this doesn't have simple solutions.

This is a follow-up for #3132

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions