Skip to content

Self doesn't work when appears in a callable directly nested in ClassVar #14108

Closed
@ilevkivskyi

Description

@ilevkivskyi

Currently this test fails

[case testTypingSelfCallableClassVar]
from typing import Self, ClassVar, Callable

class C:
    f: ClassVar[Callable[[Self], Self]]
class D(C): ...

reveal_type(D().f())  # N: Revealed type is "__main__.D"

Note, according to conventions, callable that appears directly in ClassVar should act as a method, not as an instance attribute with a callable type, i.e. in this very specific case callable needs to be made generic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-self-typesTypes for self

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions