Remove redundant generator parentheses - #5304
Merged
Merged
Conversation
Collaborator
|
Thanks! Would it be simple to extend this to all structures? Here's some examples I found: ((item.is_valid() for item in items)) # alone at top level
(((item.is_valid() for item in items)),) # tuple
[((item.is_valid() for item in items)), ""] # array (it's already handled when it's the only element)
{"foo": ((item.is_valid() for item in items))} # dictionary value |
Contributor
|
diff-shades results comparing this PR (53f837a) to main (74371e2):
|
Contributor
Author
|
Yes, that fit cleanly. I expanded this to the structures you listed and added regression cases for top-level expressions, tuple/list/dict values, nested calls, keyword/starred call args, and multi-arg calls where one pair is still required. Latest checks:
|
Boulea7
force-pushed
the
fix/2943-generator-parentheses
branch
from
August 13, 2026 03:12
5206b1e to
b216ddd
Compare
cobaltt7
approved these changes
Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #2943.
Under
--preview, this removes redundant extra parentheses around generator expressions, including standalone expressions, tuple/list/dict values, nested calls, and call arguments where Python still requires one visible pair.Checklist - did you ...
--previewstyle, following the stability policy?CHANGES.mdif necessary?Tests
.venv/bin/python -m pytest -n 4 -q(551 passed, 2 skipped, 8 subtests passed).venv/bin/python -m pytest tests/test_format.py -q(233 passed).venv/bin/pre-commit run --all-files.venv/bin/sphinx-build -a -b html -W docs/ docs/_build/