On this page
typing.Callable
Prev: typing.ByteString | Up: typing | Next: typing.cast
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.Callable
Tags: #public #python3 #stdlib #typing
Import
import typing
from typing import Callable
Signature & Overview
typing.Callable(*args, **kwargs)
Deprecated alias to collections.abc.Callable.
Usage
from typing import Callable
def apply(fn: Callable[[int, int], int], a: int, b: int) -> int:
return fn(a, b)
assert apply(lambda x, y: x + y, 3, 4) == 7
Gotchas
- Prefer
collections.abc.Callablein Python 3.9+: UseCallable[..., ReturnType]for arbitrary parameters, or aProtocolwith__call__for keyword/default arguments.
REPL Inspect
from typing import Callable
help(Callable)
Linked from
Related notes
- tuts/python3/stdlib_module/typing/ByteString Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/cast Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/typing/AbstractSet Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Annotated Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Any Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_never Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_type shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncContextManager shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncGenerator shared tags: #stdlib, #typing