From bad7ee23ad77ff6a59fce84f6b7db1b5576445ea Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Sat, 2 Aug 2025 09:30:06 -0700 Subject: [PATCH 1/2] Update unreachable.rst: mention match exhaustiveness codes from type checkers This will be useful for anyone actually trying to practically check and existing code base for exhaustive matches who is consulting this page. --- docs/guides/unreachable.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/guides/unreachable.rst b/docs/guides/unreachable.rst index d14e3cf06..2a3283e30 100644 --- a/docs/guides/unreachable.rst +++ b/docs/guides/unreachable.rst @@ -86,6 +86,8 @@ and is also present in ``typing_extensions`` starting at version 4.1. However, it is also possible to define a similar function in your own code, for example if you want to customize the runtime error message. +This use of match statements for comprehensive matching is common enough that some typecheckers have direct support for checking all match statements for exhaustiveness, regardless of whether or not they have an assert_never-style function in their default arm. For instance, in pyright this can be enabled by enabling the diagnostic code reportMatchNotExhaustive (on by default in strict mode), and in mypy it can be enabled by enabling the error code exhaustive-match. + You can also use ``assert_never()`` with a sequence of ``if`` statements: .. code:: python From 02883f794cbdb17691f8659ff5eedc8c67fdbce0 Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Fri, 8 Aug 2025 08:53:23 -0700 Subject: [PATCH 2/2] Update docs/guides/unreachable.rst: commit suggestion Co-authored-by: Sebastian Rittau --- docs/guides/unreachable.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/guides/unreachable.rst b/docs/guides/unreachable.rst index 2a3283e30..7ad519b01 100644 --- a/docs/guides/unreachable.rst +++ b/docs/guides/unreachable.rst @@ -86,7 +86,13 @@ and is also present in ``typing_extensions`` starting at version 4.1. However, it is also possible to define a similar function in your own code, for example if you want to customize the runtime error message. -This use of match statements for comprehensive matching is common enough that some typecheckers have direct support for checking all match statements for exhaustiveness, regardless of whether or not they have an assert_never-style function in their default arm. For instance, in pyright this can be enabled by enabling the diagnostic code reportMatchNotExhaustive (on by default in strict mode), and in mypy it can be enabled by enabling the error code exhaustive-match. +This use of match statements for comprehensive matching is common +enough that some typecheckers have direct support for checking all match +statements for exhaustiveness, regardless of whether or not they have an +``assert_never``-style function in their default arm. For instance, in pyright +this can be enabled by enabling the diagnostic code ``reportMatchNotExhaustive`` +(on by default in strict mode), and in mypy it can be enabled by enabling +the error code ``exhaustive-match``. You can also use ``assert_never()`` with a sequence of ``if`` statements: