Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Jul 10, 2024

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.

Copy link
Contributor

github-actions bot commented Jul 10, 2024

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 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
@MichaReiser MichaReiser merged commit bd01004 into main Jul 11, 2024
20 checks passed
@MichaReiser MichaReiser deleted the if-leading-comment branch July 11, 2024 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the 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