Skip to content

Pattern matching: case guards make match non-exhaustive #16223

Closed as not planned
@outring

Description

Bug Report

Looks like case guards make match non-exhaustive even when having wildcard case

To Reproduce

def do_thing(s: str) -> str:
    match s:
        case str(x) if x == "something":
            return x
        case _:
            return ""

Expected Behavior

No error

Actual Behavior

error: Missing return statement  [return]

Your Environment

  • Mypy version used: 1.5.1
  • Mypy command-line flags: --install-types --non-interactive
  • Mypy configuration options from mypy.ini (and other config files):
    [tool.mypy]
    python_version = "3.11"
    strict = true
    warn_unused_configs = true
    disallow_untyped_decorators = false
    
  • Python version used: 3.11.4

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-match-statementPython 3.10's match statement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions