Is it possible to typedef a function?

Viewed 213

For example, in C I might write:

typedef Foo (*MapCtx)(void * item, void * ctx);

// and now 'MapCtx' is a type

In Python 3, I have a function:

map(item: Any, ctx: Optional[Any] = None, caster: Callable[[Any],Any]=lambda x: x)

Where the caster is more or less a callback handle intended to operate on the return value (to clean up the call if I need a type converter in there).

What I would like to do is define this as a type, and accept that type in a body of functions and class methods.

How would I do that in Python 3?

0 Answers
Related