Skip to content

Use space separator before parenthesiszed expressions in comprehensions with leading comments. - #12282

Merged
MichaReiser merged 1 commit into
mainfrom
if-leading-comment
Jul 11, 2024
Merged

MichaReiser merged 1 commit into
mainfrom
if-leading-comment

Conversation

@MichaReiser

@MichaReiser MichaReiser commented Jul 10, 2024 •

Copy link
Copy Markdown
Member

Summary

Keeps the parentheses on the same line as the preceding keyword if the following expression has leading comments.

Fixes #12280

y = [
    a
    for (
        # comment
        a
    ) in (
        # comment
        x
    )
    if (
        # asdasd
        "askldaklsdnmklasmdlkasmdlkasmdlkasmdasd"
        != "as,mdnaskldmlkasdmlaksdmlkasdlkasdm"
        and "zxcm,.nzxclm,zxnckmnzxckmnzxczxc" != "zxcasdasdlmnasdlknaslkdnmlaskdm"
    )
    if (
        # comment
        x
    )
]

Test Plan

I added three new integration tests.

The changes are gated behind preview because this isn't a fix addressing a stability issue or because the formatted produced invalid sytnax.

@github-actions

github-actions Bot commented Jul 10, 2024 •

Copy link
Copy Markdown
Contributor

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 parse examples/chatgpt/gpt_actions_library/.gpt_action_getting_started.ipynb:11:1:1: Expected an expression
error: Failed to parse examples/chatgpt/gpt_actions_library/gpt_action_bigquery.ipynb:13:1:1: Expected an expression

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 parse examples/chatgpt/gpt_actions_library/.gpt_action_getting_started.ipynb:11:1:1: Expected an expression
error: Failed to parse examples/chatgpt/gpt_actions_library/gpt_action_bigquery.ipynb:13:1:1: Expected an expression

@MichaReiser
MichaReiser force-pushed the if-leading-comment branch 2 times, most recently from 02d8264 to c2c1c3c Compare July 10, 2024 21:05
@MichaReiser MichaReiser added formatter Related to the Ruff formatter preview Related to preview-mode features labels Jul 10, 2024
@MichaReiser MichaReiser changed the title Use space separator between if and ( in comprehensions Use space separator before parenthesiszed expressions in comprehensions with leading comments. Jul 11, 2024
@MichaReiser
MichaReiser marked this pull request as ready for review July 11, 2024 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

formatter Related to the Ruff formatter preview Related to preview-mode features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Odd formatting choice for long conditions with comments in list/dict comprehensions

2 participants