Skip to content

Comments

Fix bracket spacing for single-element tuples in f-string expressions#15537

Merged
MichaReiser merged 1 commit intomainfrom
micha/f-string-tuple
Jan 17, 2025
Merged

Fix bracket spacing for single-element tuples in f-string expressions#15537
MichaReiser merged 1 commit intomainfrom
micha/f-string-tuple

Conversation

@MichaReiser
Copy link
Member

Summary

Fixes #15535 (comment)

The formatter always parenthesizes single-element tuples even if they weren't in the source.
This lead to an instability before where the formatter added spacing around the f-strings { {}, } that
then were removed when reformatting the code because the tuple's now parenthesized {({},)}.

Test Plan

Added test. I reviewed our other expression formatting and I didn't find any
other, except generators, that introduce parentheses. For generators, unparenthesized
generators aren't allowed in an expression context.

@MichaReiser MichaReiser added bug Something isn't working formatter Related to the formatter labels Jan 16, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jan 16, 2025

ruff-ecosystem results

Formatter (stable)

ℹ️ ecosystem check encountered format errors. (no format changes; 1 project error)

openai/openai-cookbook (error)

warning: Detected debug build without --no-cache.
error: Failed to read examples/Assistants_API_overview_python.ipynb: Expected a Jupyter Notebook, which must be internally stored as JSON, but this file isn't valid JSON: expected `,` or `]` at line 197 column 8

Formatter (preview)

ℹ️ ecosystem check encountered format errors. (no format changes; 1 project error)

openai/openai-cookbook (error)

ruff format --preview

warning: Detected debug build without --no-cache.
error: Failed to read examples/Assistants_API_overview_python.ipynb: Expected a Jupyter Notebook, which must be internally stored as JSON, but this file isn't valid JSON: expected `,` or `]` at line 197 column 8

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@MichaReiser MichaReiser enabled auto-merge (squash) January 17, 2025 07:58
@MichaReiser MichaReiser merged commit 9ed67ba into main Jan 17, 2025
20 checks passed
@MichaReiser MichaReiser deleted the micha/f-string-tuple branch January 17, 2025 08:02
dcreager added a commit that referenced this pull request Jan 17, 2025
* main:
  [red-knot] Inline `SubclassOfType::as_instance_type_of_metaclass()` (#15556)
  [`flake8-comprehensions`] strip parentheses around generators in `unnecessary-generator-set` (`C401`) (#15553)
  [`pylint`] Implement `redefined-slots-in-subclass` (`W0244`) (#9640)
  [`flake8-bugbear`] Do not raise error if keyword argument is present and target-python version is less or equals than 3.9 (`B903`) (#15549)
  [red-knot] `type[T]` is disjoint from `type[S]` if the metaclass of `T` is disjoint from the metaclass of `S` (#15547)
  [red-knot] Pure instance variables declared in class body (#15515)
  Update snapshots of #15507 with new annotated snipetts rendering (#15546)
  [`pylint`] Do not report methods with only one `EM101`-compatible `raise` (`PLR6301`) (#15507)
  Fix unstable f-string formatting for expressions containing a trailing comma (#15545)
  Support `knot.toml` files in project discovery (#15505)
  Add support for configuring knot in `pyproject.toml` files (#15493)
  Fix bracket spacing for single-element tuples in f-string expressions (#15537)
  [`flake8-simplify`] Do not emit diagnostics for expressions inside string type annotations (`SIM222`, `SIM223`) (#15405)
  [`flake8-pytest-style`] Do not emit diagnostics for empty `for` loops (`PT012`, `PT031`) (#15542)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working formatter Related to the formatter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Brace spacing when formatting f-strings is not idempotent

2 participants