From 793b036c76c58bcf4a64c21a08e2c1fe2a9ae3a9 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 27 Mar 2025 20:44:39 +0900 Subject: [PATCH 1/2] Add TYPE_CHECKING builtin --- Python/bltinmodule.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 6709f306bb024d..f0422680fa625d 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -3407,6 +3407,7 @@ _PyBuiltin_Init(PyInterpreterState *interp) SETBUILTIN("tuple", &PyTuple_Type); SETBUILTIN("type", &PyType_Type); SETBUILTIN("zip", &PyZip_Type); + SETBUILTIN("TYPE_CHECKING", Py_False); debug = PyBool_FromLong(config->optimization_level == 0); if (PyDict_SetItemString(dict, "__debug__", debug) < 0) { Py_DECREF(debug); From 73412a8a92f4ef97b66853d09f7d47112078a256 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 27 Mar 2025 20:49:09 +0900 Subject: [PATCH 2/2] Add doc --- Doc/library/constants.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Doc/library/constants.rst b/Doc/library/constants.rst index c0ac4ea8412ebd..645ae77b1bb0f8 100644 --- a/Doc/library/constants.rst +++ b/Doc/library/constants.rst @@ -70,6 +70,15 @@ A small number of constants live in the built-in namespace. They are: ``Ellipsis`` is the sole instance of the :data:`types.EllipsisType` type. +.. data:: TYPE_CHECKING + + This constant is same to :data:`typing.TYPE_CHECKING`. + It is always ``False`` at runtime, but third party static type checkers + assumes it to be ``True``. + + .. versionadded:: next + + .. data:: __debug__ This constant is true if Python was not started with an :option:`-O` option.