Skip to content

RUF031: False positive when using with unpacking  #12776

@alexfikl

Description

@alexfikl

The following run should not indicate any errors

>> ruff check --isolated --preview --select RUF031 --target-version py38 subscript-tuple.py
subscript-tuple.py:1:3: RUF031 [*] Avoid parentheses for tuples in subscripts.
|
1 | d[(*indices, 5)]
|   ^^^^^^^^^^^^^ RUF031
|
= help: Remove the parentheses.

Found 1 error.
[*] 1 fixable with the `--fix` option.

As far as I know, d[*indices, 5] is invalid syntax on Python 3.8, but should work for Python >=3.9 (with the new PEG parser, I think? definitely works on 3.12).

Expected result:

  • No errors / fixes reported when setting --target-version py38.
  • The recommended fix when setting --target-version py39 and above.

xref: CI failure resulting from the fix: https://github.com/inducer/pymbolic/actions/runs/10315281929/job/28555159989?pr=144

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions