返回另一个函数“->”符号的函数

What is the -> symbol for returning a function from another function?

def OneFunc(x) -> def:
    return AnotherFunc

Does not seem to work, neither function or func ..

评论
毁灭
毁灭

You want the Callable generic type.

from typing import Callable

def OneFunc(x: int) -> Callable[[], None]:
    return lambda: AnotherFunc('5', x)

The parameters to Callable depend on the signature of the function you're returning.

点赞
评论