Skip to content

False positive "Missing return statement" for coroutine result pattern matching #17306

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

Closed
zoola969 opened this issue May 31, 2024 · 1 comment
Labels
bug mypy got something wrong topic-match-statement Python 3.10's match statement

Comments

@zoola969
Copy link

Bug Report

When using direct coroutine call in pattern matching construction, mypy complains about missing return statement.
But if the coroutine result previously has been assigned to a variable, and the variable was used in pattern matching then mypy is good with it

To Reproduce

async def func() -> bool | str:
    return "a"


async def test_1() -> str:
    match await func():
        case str(s):
            return s
        case bool(bool_var):
            match bool_var:
                case True:
                    return "true"
                case False:
                    return "false"


async def test_2() -> str:
    r = await func()
    match r:
        case str(s):
            return s
        case bool(bool_var):
            match bool_var:
                case True:
                    return "true"
                case False:
                    return "false"

Expected Behavior

No errors

Actual Behavior

example.py: note: In function "test_1":
example.py:5: error: Missing return statement  [return]
    async def test_1() -> str:
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.10.0
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
    pyproject.toml
[tool.mypy]
check_untyped_defs = true
enable_error_code = "explicit-override,unused-awaitable,ignore-without-code,truthy-bool,possibly-undefined,redundant-expr,redundant-self"
plugins = "sqlalchemy.ext.mypy.plugin"
pretty = true
show_error_context = true
strict = true
warn_unreachable = true
  • Python version used: 3.12.2
@zoola969 zoola969 added the bug mypy got something wrong label May 31, 2024
@JelleZijlstra JelleZijlstra added the topic-match-statement Python 3.10's match statement label May 31, 2024
@JelleZijlstra
Copy link
Member

Duplicate of #17230

@JelleZijlstra JelleZijlstra marked this as a duplicate of #17230 May 31, 2024
@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2024
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