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

reveal_type not run in "unreachable" branches #18423

Open
hjwp opened this issue Jan 6, 2025 · 0 comments
Open

reveal_type not run in "unreachable" branches #18423

hjwp opened this issue Jan 6, 2025 · 0 comments
Labels
bug mypy got something wrong

Comments

@hjwp
Copy link

hjwp commented Jan 6, 2025

Bug Report

It looks like reveal_type() doesn't work in "unreachable" branches, ie places where assert_never() passes.

To Reproduce

from typing import assert_never, reveal_type


def foo(b: bool):
    reveal_type(b)
    match b:
        case True:
            reveal_type(b)
            print("True")
        case False:
            reveal_type(b)
            print("False")
        case _:
            assert_never(b)
            reveal_type(b)  # this one does not print

(also at https://mypy-play.net/?mypy=latest&python=3.12&gist=d2646350c3ec4aa892763cdda7d32201)

Actual Behavior

❯ mypy thing.py
thing.py:5: note: Revealed type is "builtins.bool"
thing.py:8: note: Revealed type is "Literal[True]"
thing.py:11: note: Revealed type is "Literal[False]"
Success: no issues found in 1 source file

Expected behaviour

I would expect the 4th reveal_type() to print something like Revealed type is Never ?

(note that the assert_never() does "pass").

Your Environment

mypy 1.14.1 (compiled: yes)
Python 3.13.0 (also seen in 3.12)

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

Successfully merging a pull request may close this issue.

1 participant