Skip to content

[feature] Get the type from a variable #769

@Dimitri-WEI-Lingfeng

Description

@Dimitri-WEI-Lingfeng

Feature
A similar feature in typescript

const foo: number = 1
type Foo = typeof foo  // type Foo = number

function bar(x: string): void {

}

type Bar = typeof bar // type Bar = (x: string) => void

Pitch
The expected way in future python.
Possible implementation: implement __class_getitem__ for type :

foo: int = 1
Foo = type[foo]  # equivalent to Foo = int

def bar(x: string) -> None :
    ...
Bar = type[bar]  # equivalent to Bar = Callable[[str], None]

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: featureDiscussions about new features for Python's type annotations

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions