Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not advertise to create your own assert_never helper #15947

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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