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

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

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

MichaReiser
Copy link
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
Copy link
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
20 checks passed
@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