Skip to content

Parenthesize singleton tuples in yield expressions#5170

Open
wayyoungboy wants to merge 1 commit into
psf:mainfrom
wayyoungboy:fix-yield-singleton-tuple-3851
Open

Parenthesize singleton tuples in yield expressions#5170
wayyoungboy wants to merge 1 commit into
psf:mainfrom
wayyoungboy:fix-yield-singleton-tuple-3851

Conversation

@wayyoungboy

@wayyoungboy wayyoungboy commented Jun 6, 2026

Copy link
Copy Markdown

Fixes #3851.

Summary

  • normalize yield expressions so bare singleton tuple yields like yield x, become yield (x,)
  • preserve required parentheses around yield walrus expressions
  • add a formatting fixture for singleton tuple yield expressions

Tests

  • tests/test_format.py::test_simple_format[yield_singleton_tuple] (RED before fix)
  • tests/test_format.py
  • tests/test_black.py::BlackTestCase::test_get_features_used
  • git diff --cached --check

@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

diff-shades results comparing this PR (85ccc76) to main (ce1897a):

--preview style (View full diff):
╭─────────────────────── Summary ────────────────────────╮
│ 2 projects & 6 files changed / 79 changes [+53/-26]    │
│                                                        │
│ ... out of 2 954 857 lines, 13 912 files & 22 projects │
╰────────────────────────────────────────────────────────╯

Differences found.

--stable style (View full diff):
╭─────────────────────── Summary ────────────────────────╮
│ 2 projects & 6 files changed / 79 changes [+53/-26]    │
│                                                        │
│ ... out of 2 954 857 lines, 13 912 files & 22 projects │
╰────────────────────────────────────────────────────────╯

Differences found.


What is this? | Workflow run | diff-shades documentation

@cobaltt7

cobaltt7 commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks! This change affects more than just singleton yield tuples, it makes yield statements with any tuple behave more like functions in general, but I think this is a good change overall for consistency.

This changes Black's formatting, so it needs to be gated to the Preview style. See 01c29bd for a good recent example of how to do this. Please also add a changelog entry.

@wayyoungboy

Copy link
Copy Markdown
Author

谢谢!这个变化不仅影响单元组,还让任何元组的语句更像函数,但我认为总体来说这是个好变化,有助于一致性。yield``yield

这改变了Black的格式,因此需要将它限制为预览样式。请参见01c29bd,那里有一个很好的近期示例。请同时添加更新日志条目。

Makes sense. I’ll move this behind preview style and add the changelog entry.

@wayyoungboy wayyoungboy force-pushed the fix-yield-singleton-tuple-3851 branch from 85ccc76 to 2ebaa3f Compare June 12, 2026 16:51
@wayyoungboy

Copy link
Copy Markdown
Author

Updated.

@wayyoungboy wayyoungboy force-pushed the fix-yield-singleton-tuple-3851 branch from 2ebaa3f to 6db8407 Compare June 12, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

single element tuples in yield expressions are not parenthesized

2 participants