Skip to content

False positive: invalid-syntax alternative patterns bind different names #21360

@BarrensZeppelin

Description

@BarrensZeppelin

Summary

This file produces an invalid-syntax error, but it contains valid syntax:

import ast

match None:
    case ast.Subscript(n, ast.Constant() | ast.Slice()) | ast.Attribute(n):
        pass

https://play.ruff.rs/a88bae2d-d65a-4495-a33d-384a09fbbb4f

If I remove | ast.Slice(), the error goes away, so it seems like state is incorrectly shared between different alternative patterns.

Version

ruff 0.14.4

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