Skip to content

Improve type inference for recursive protocols #3829

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy