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

(🎁) Support typing.assert_never (and the one from typing_extensions) #12399

Closed
KotlinIsland opened this issue Mar 21, 2022 · 3 comments
Closed
Labels

Comments

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Mar 21, 2022

def assert_never(__arg: Never) -> Never: 
    """Custom impl for demonstration purposes only. (mypy doesn't have stubs for the real one)"""
    ...

assert_never()  # no error

Mypy should report an error when assert_never is used in a position that is reachable.

Related: #12253

@JelleZijlstra
Copy link
Member

Your example gives two straightforward errors (Never is not defined and assert_never() takes one argument).

This fixed version behaves as expected:

from typing import NoReturn as Never

def assert_never(__arg: Never) -> Never: 
    """Custom impl for demonstration purposes only. (mypy doesn't have stubs for the real one)"""
    ...

def f(x: bool):
    assert_never(x)  # error
    if x is True:
        pass
    elif x is False:
        pass
    else:
        assert_never(x)  # no error

Can you clarify what you think is wrong?

typing.assert_never shouldn't need any specific support in mypy because the stubs are sufficient.

@KotlinIsland
Copy link
Contributor Author

😳

True, sorry about that.

@KotlinIsland
Copy link
Contributor Author

@JelleZijlstra Why does Never/raise suppress unreachable errors? #10916

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants