From 6ab5118024ebf06e30c309173969116b4ce2390b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Thu, 15 Jan 2026 13:49:37 -0300 Subject: [PATCH] Mention typing.Never used to type hint empty containers --- Doc/library/typing.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index eaa0ba54af18e7..f03c60c993dd36 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -973,6 +973,16 @@ using ``[]``. case _: never_call_me(arg) # OK, arg is of type Never (or NoReturn) + Or to define an empty container that must remain empty:: + + from typing import Never + + empty_list: list[Never] = [] + empty_list.append(1) # type checker error + + empty_dict: dict[Never, Never] = {} + empty_dict['key'] = 'value' # type checker error + :data:`!Never` and :data:`!NoReturn` have the same meaning in the type system and static type checkers treat both equivalently.