Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ntBre
Copy link
Contributor

@ntBre ntBre commented Mar 7, 2025

Summary

This PR reuses a slightly modified version of the check_tuple_unpacking method added for detecting unpacking in return and yield statements to detect the same issue in the iterator clause of for loops.

I ran into the same issue with a bare for x in *rest: ... example (invalid even on Python 3.13) and added it as a comment on #16520.

I considered just making this an additional StarTupleKind variant as well, but this change was in a different version of Python, so I kept it separate.

Test Plan

New inline tests.

before Python 3.9

Summary
--

This PR reuses a slightly modified version of the `check_tuple_unpacking` method
added for detecting unpacking in `return` and `yield` statements to detect the
same issue in the iterator clause of `for` loops.

I ran into the same issue with a bare `for x in *rest: ...` example (invalid on
every Python) and added it as a comment on
#16520.

I considered just making this an additional `StarTupleKind` variant as well, but
this change was in a different version of Python, so I kept it separate.

Test Plan
--

New inline tests.
@ntBre ntBre added parser Related to the parser preview Related to preview mode features labels Mar 7, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@ntBre ntBre merged commit 2382fe1 into main Mar 13, 2025
21 checks passed
@ntBre ntBre deleted the brent/syn-unpacking-for-loop branch March 13, 2025 19:55
dcreager added a commit that referenced this pull request Mar 14, 2025
* main: (53 commits)
  [syntax-errors] Tuple unpacking in `for` statement iterator clause before Python 3.9 (#16558)
  Ruff v0.10 Release (#16708)
  Add new `noqa` specification to the docs (#16703)
  describe requires-python fallback in docs (#16704)
  [red-knot] handle cycles in MRO/bases resolution (#16693)
  [red-knot] Auto generate statement nodes (#16645)
  [`pylint`] Better inference for `str.strip` (`PLE310`) (#16671)
  [`pylint`] Improve `repeated-equality-comparison` fix to use a `set` when all elements are hashable (`PLR1714`) (#16685)
  [`pylint`/`pep8-naming`] Check `__new__` argument name in `bad-staticmethod-argument` and not `invalid-first-argument-name-for-class-method` (`PLW0211`/`N804`) (#16676)
  [`flake8-pyi`] Stabilize fix for `unused-private-type-var` (`PYI018`) (#16682)
  [`flake8-bandit`] Deprecate `suspicious-xmle-tree-usage` (`S320`) (#16680)
  [`flake8-simplify`] Avoid double negation in fixes (`SIM103`) (#16684)
  [`pyupgrade`]: Improve diagnostic range for `redundant-open-mode` (`UP015`) (#16672)
  Consider all `TYPE_CHECKING` symbols for type-checking blocks (#16669)
  [`pep8-naming`]: Ignore methods decorated with `@typing.override` (`invalid-argument-name`) (#16667)
  Stabilize FURB169 preview behavior (#16666)
  [`pylint`] Detect invalid default value type for `os.environ.get` (`PLW1508`) (#16674)
  [`flake8-pytest-style`] Allow for loops with empty bodies (`PT012`, `PT031`) (#16678)
  [`pyupgrade`]: Deprecate `non-pep604-isinstance` (`UP038`) (#16681)
  [`flake8-type-checking`] Stabilize `runtime-cast-value` (`TC006`) (#16637)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parser Related to the parser preview Related to preview mode features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants