Skip to content

Generic Self Type classmethods behave incorrectly on instances #3630

@rowillia

Description

@rowillia

Repro:

from typing import TypeVar, Tuple, Type

T = TypeVar('T', bound='Friend')

class Friend:
    other = None  # type: Friend

    @classmethod
    def make(cls: Type[T]) -> T:
        return cls()

class SuperFriend(Friend):
    pass

reveal_type(SuperFriend.make())  # Revealed type is 'test_generic_self.SuperFriend*'
reveal_type(SuperFriend().make())  # Revealed type is '<nothing>'

Both invocations should return test_generic_self.SuperFriend*.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions