ruff
90c8571b - [PT006] Fix syntax error when unpacking nested tuples in parametrize fixes (#22441) (#22464)

Commit
1 day ago
[PT006] Fix syntax error when unpacking nested tuples in parametrize fixes (#22441) (#22464) ## Summary Fixes a syntax error bug in the `PT006` rule where applying fixes could generate invalid Python code. **Problem**: When unpacking nested tuples in `pytest.mark.parametrize` decorators, Ruff's code generator unparses tuples without outer parentheses at level 0 (e.g., `(1, 2)` becomes `1, 2` and `((1,),)` becomes `(1,),`). This caused syntax errors like `[1, 2,]` or `[(1,),,]` when used as list elements. **Solution**: Introduced two helper functions in `parametrize.rs`: - `is_parenthesized`: Validates if a string is fully enclosed in matching parentheses - `unparse_expr_in_sequence`: Ensures non-empty tuples are always parenthesized when used as sequence elements Fixes https://github.com/astral-sh/ruff/issues/22441 ## Test Plan - Added comprehensive regression tests to `PT006.py` covering: - Single-element nested empty tuples: `((),)` - Single-element nested single-value tuples: `((1,),)` - Single-element nested multi-value tuples: `((1, 2),)` - Deeply nested structures: `(((1,),),)` - Mixed types: `("hello",,)`, `([1, 2],,)` - Verified edge cases with automated snapshot testing: - All 47 existing flake8-pytest-style tests continue to pass - Updated snapshots: `PT006_default.snap`, `PT006_csv.snap`, `PT006_list.snap` --------- Co-authored-by: Brent Westbrook <brentrwestbrook@gmail.com>
Author
Parents
Loading