Skip to content

Commit bad7ee2

Browse files
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.
1 parent c141cdf commit bad7ee2

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

docs/guides/unreachable.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ and is also present in ``typing_extensions`` starting at version 4.1.
8686
However, it is also possible to define a similar function in your own
8787
code, for example if you want to customize the runtime error message.
8888

89+
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.
90+
8991
You can also use ``assert_never()`` with a sequence of ``if`` statements:
9092

9193
.. code:: python

0 commit comments

Comments
 (0)