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

match narrowing fails when the operand is an await expression #17230

Open
tamird opened this issue May 9, 2024 · 0 comments
Open

match narrowing fails when the operand is an await expression #17230

tamird opened this issue May 9, 2024 · 0 comments
Labels
bug mypy got something wrong topic-match-statement Python 3.10's match statement

Comments

@tamird
Copy link
Contributor

tamird commented May 9, 2024

This is related to #12998.

https://mypy-play.net/?mypy=latest&python=3.12&gist=42bbd2ec432dbfd003429c64b8dc7435

from typing import assert_never

async def fn() -> int | None:
    return None

async def foo() -> None:
    match await fn(): 
        case int():
            pass
        case None:
            pass
        case never:
            assert_never(never) # error: Argument 1 to "assert_never" has incompatible type "int | None"; expected "NoReturn"  [arg-type]
            
async def bar() -> None:
    a = fn()
    match await a: 
        case int():
            pass
        case None:
            pass
        case never:
            assert_never(never) # error: Argument 1 to "assert_never" has incompatible type "int | None"; expected "NoReturn"  [arg-type]
            
async def baz() -> None:
    match _a := await fn(): 
        case int():
            pass
        case None:
            pass
        case never:
            assert_never(never) # works!

I also sent #17199 with a test case that demonstrates the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-match-statement Python 3.10's match statement
Projects
None yet
Development

No branches or pull requests

2 participants