From 3e036946f4eab5bc620809bb503018ce4d873814 Mon Sep 17 00:00:00 2001 From: Cheserem Titus <50730372+cheseremtitus24@users.noreply.github.com> Date: Thu, 6 Jul 2023 22:14:05 +0300 Subject: [PATCH] Update cheat_sheet_py3.rst 2 properly xplain Callable There was a bit of a gap as to which part are the input and where the return type is. --- docs/source/cheat_sheet_py3.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/source/cheat_sheet_py3.rst b/docs/source/cheat_sheet_py3.rst index 297427e72aca..f4ee00974715 100644 --- a/docs/source/cheat_sheet_py3.rst +++ b/docs/source/cheat_sheet_py3.rst @@ -109,8 +109,11 @@ Functions x.anything() + 1 + "string" # no errors # This is how you annotate a callable (function) value + Callable[[A1, A2, A3], Rt] represents a function with three arguments with types A1, A2, and A3, respectively. The return type of the function is Rt. x: Callable[[int, float], float] = f def register(callback: Callable[[str], int]) -> None: ... + Callable[..., ReturnType] (literal ellipsis) can be used to type hint a callable taking any number of arguments and returning ReturnType + ReturnType can only be of a single type. # A generator function that yields ints is secretly just a function that # returns an iterator of ints, so that's how we annotate it