Skip to content

Fallback of recursive types to Any in return types of generic methods #1157

@sharkdp

Description

@sharkdp

Summary

In the following snippet, the return type of wrap falls back to Wrapper[Any | None]. Note that this only happens if wrap itself is generic. When the (dummy) generic context [S] is removed, the return type is Wrapper[Recursive], as expected:

type Recursive = Recursive | None

class Wrapper[T]: ...

class C[T]:
    @staticmethod
    def wrap[S]() -> Wrapper[T]:
        return Wrapper()

reveal_type(C[Recursive].wrap())  # Wrapper[Any | None]

https://play.ty.dev/14d6e89f-8f51-4322-a862-c14799c67e9a

Version

current main (25853e237)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggenericsBugs or features relating to ty's generics implementation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions