Skip to content

error for incompatible capture type is missing line number #20259

@asottile

Description

@asottile

Bug Report

boiled down from code here

(A clear and concise description of what the bug is.)

To Reproduce

data = [100, 200, 300, 400]
match data:
    case [*start, 400]:
        print(f"Ends with 400, start: {start}")
    case [100, *rest]:
        print(f"Starts with 100, rest: {rest}")
config = {"host": "localhost", "port": 8080, "debug": True, "timeout": 30}
match config:
    case {"host": h, "port": p, **rest}:
        print(f"Server: {h}:{p}, other settings: {rest}")

Expected Behavior

the error message should mention the line number (I believe 9 in this case)

Actual Behavior

$ mypy t.py
t.py: error: Incompatible types in capture pattern (pattern captures type "dict[str, object]", variable has type "list[int]")  [misc]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.18.2
  • Mypy command-line flags: n/a
  • Mypy configuration options from mypy.ini (and other config files): n/a
  • Python version used: 3.12.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions