From bc8a08c0df96fde0f886b954eb87141ee02453c9 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 17 Feb 2021 10:11:39 -0700 Subject: [PATCH] Add Void type --- Lib/typing.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Lib/typing.py b/Lib/typing.py index 6224930c3b0275..ee13541487caa0 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -402,6 +402,24 @@ def stop() -> NoReturn: """ raise TypeError(f"{self} is not subscriptable") +@_SpecialForm +def Void(self, parameters): + """Special type indicating functions that do not return values. + Example:: + + from typing import Void, Any + + def nothing() -> Void: + pass + + nothing() #passes type checking + a: Any = nothing() #fails type checking + + This type is invalid in any context other than a function/method return + type annotation, e.g., ``List[Void]`` will fail in static type checkers. + """ + raise TypeError(f"{self} is not subscriptable") + @_SpecialForm def ClassVar(self, parameters): """Special type construct to mark class variables.