Skip to content

Commit dc73445

Browse files
authored
Do not advertise to create your own assert_never helper (python#15947)
1 parent 4077dc6 commit dc73445

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

docs/source/literal_types.rst

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,10 @@ perform an exhaustiveness check, you need to update your code to use an
329329
.. code-block:: python
330330
331331
from typing import Literal, NoReturn
332+
from typing_extensions import assert_never
332333
333334
PossibleValues = Literal['one', 'two']
334335
335-
def assert_never(value: NoReturn) -> NoReturn:
336-
# This also works at runtime as well
337-
assert False, f'This code should never be reached, got: {value}'
338-
339336
def validate(x: PossibleValues) -> bool:
340337
if x == 'one':
341338
return True
@@ -443,10 +440,7 @@ Let's start with a definition:
443440
444441
from enum import Enum
445442
from typing import NoReturn
446-
447-
def assert_never(value: NoReturn) -> NoReturn:
448-
# This also works in runtime as well:
449-
assert False, f'This code should never be reached, got: {value}'
443+
from typing_extensions import assert_never
450444
451445
class Direction(Enum):
452446
up = 'up'

0 commit comments

Comments
 (0)