python / python/mypy

Exhaustiveness of type tuple[bool, bool]

Open
#21,968 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-match-statement topic-reachability
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

It looks like the exhaustiveness of tuples of bools is not checked in match statements.

To Reproduce

def measure(a: bool, b: bool) -> float:
    match a, b:
        case True, True:
            return 1
        case True, False:
            return 0.9
        case False, True:
            return 0.5
        case False, False:
            return 0

Expected Behavior

Should pass, looks exhaustive to me (or I should go take a nap).

Actual Behavior

$ mypy --enable-error-code exhaustive-match repro.py
repro.py:1: error: Missing return statement  [return]
repro.py:2: error: Match statement has unhandled case for values of type "tuple[bool, bool]"  [exhaustive-match]
repro.py:2: note: If match statement is intended to be non-exhaustive, add `case _: pass`
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 2.3.1 (compiled: yes)
  • Mypy command-line flags: --enable-error-code exhaustive-match
  • Mypy configuration options from mypy.ini (and other config files): ø
  • Python version used: 3.14.7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the provided repro with Python 3.14.7 and --enable-error-code exhaustive-match, then trace how exhaustive-match analysis handles tuple[bool, bool] in match statements. Done means the four boolean cases are recognized as exhaustive without a missing-return or unhandled-case error, while genuinely incomplete matches still report errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.