Skip to content

Erroneous "Alternative patterns bind different names" in match statement #13950

@zach-waggoner

Description

@zach-waggoner

Bug Report

In a match statement, mypy complains that a case block binds different names in alternative patterns, but this is not the case.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.10&gist=68e7e816223c64a1e05a12d5935930c1

subject = "" match subject: case [str(s)] | str(s): pass

Expected Behavior

Mypy finds no errors since each alternative pattern binds the same variable (s).

Actual Behavior

main.py:4: error: Alternative patterns bind different names Found 1 error in 1 file (checked 1 source file) 

Your Environment

  • Mypy version used: 0.981
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.10

Metadata

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