Skip to content

Syntax error false positive on nested alternative patterns #21101

@ntBre

Description

@ntBre

This change seems to now cause a SyntaxError on the following valid code that doesn't use different names:

invalid-syntax: alternative patterns bind different names
   --> src/sp_repo_review/checks/ruff.py:127:17
    |
125 |           match ruff:
126 |               case (
127 | /                 {"lint": {"select": x} | {"extend-select": x}}
128 | |                 | {"select": x}
129 | |                 | {"extend-select": x}
    | |______________________________________^
130 |               ):
131 |                   return cls.code in x or "ALL" in x
    |

See scientific-python/cookie#663

Originally posted by @henryiii in #20682 (comment)

and here's a minimized example:

match ruff:
    case {"lint": {"select": x} | {"extend-select": x}} | {"select": x}:
        return cls.code in x or "ALL" in x

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions