Skip to content

Fix incorrect placement of leading function comment with type params#12447

Merged
MichaReiser merged 1 commit intomainfrom
leading-function-def-comment-with-type-params
Jul 22, 2024
Merged

Fix incorrect placement of leading function comment with type params#12447
MichaReiser merged 1 commit intomainfrom
leading-function-def-comment-with-type-params

Conversation

@MichaReiser
Copy link
Copy Markdown
Member

Summary

Fixes #12430

@decorator
# remark
def foo[S](x: S) -> S: ...

was formatted to

@decorator
def foo# remark
[S](x: S) -> S: ...

This PR marks the # remark as dangling comment and formats it between the decorator and the function header.

Test Plan

Added tests. I also added test for classes.

@MichaReiser MichaReiser added bug Something isn't working formatter Related to the formatter labels Jul 22, 2024
@github-actions
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_canvaslms.ipynb:15:1:1: Expected an expression
error: Failed to parse examples/chatgpt/gpt_actions_library/gpt_action_outlook.ipynb:13:1:1: Expected an expression
error: Failed to parse examples/chatgpt/gpt_actions_library/gpt_action_salesforce.ipynb:17:1:13: Simple statements must be separated by newlines or semicolons

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_canvaslms.ipynb:15:1:1: Expected an expression
error: Failed to parse examples/chatgpt/gpt_actions_library/gpt_action_outlook.ipynb:13:1:1: Expected an expression
error: Failed to parse examples/chatgpt/gpt_actions_library/gpt_action_salesforce.ipynb:17:1:13: Simple statements must be separated by newlines or semicolons

@MichaReiser MichaReiser merged commit ed238e0 into main Jul 22, 2024
@MichaReiser MichaReiser deleted the leading-function-def-comment-with-type-params branch July 22, 2024 12:17
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.

Formatter produces invalid python code if comment between decorator and PEP695 function

2 participants