Skip to content

Commit

Permalink
Do not advertise to create your own assert_never helper (#15947)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn authored Aug 24, 2023
1 parent 4077dc6 commit dc73445
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions docs/source/literal_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,10 @@ perform an exhaustiveness check, you need to update your code to use an
.. code-block:: python
from typing import Literal, NoReturn
from typing_extensions import assert_never
PossibleValues = Literal['one', 'two']
def assert_never(value: NoReturn) -> NoReturn:
# This also works at runtime as well
assert False, f'This code should never be reached, got: {value}'
def validate(x: PossibleValues) -> bool:
if x == 'one':
return True
Expand Down Expand Up @@ -443,10 +440,7 @@ Let's start with a definition:
from enum import Enum
from typing import NoReturn
def assert_never(value: NoReturn) -> NoReturn:
# This also works in runtime as well:
assert False, f'This code should never be reached, got: {value}'
from typing_extensions import assert_never
class Direction(Enum):
up = 'up'
Expand Down

0 comments on commit dc73445

Please sign in to comment.