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

Parenthesize long type annotations in annotated assignments #9210

Merged

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Dec 20, 2023

Summary

This PR implements #8894 for annotated assignments. It intentionally excludes annotations in function definition because we're internally discussing whether we support the changes or not.

Test Plan

Ran the ecosystem check and there are.... no changes! Which is rather disappointing. I checked the diff shades output from the Black changes and verified that ruff formats the one shade the same as black.
I ran the similarity index script and verified that the numbers remain unchanged.

@MichaReiser MichaReiser added formatter Related to the formatter preview Related to preview mode features labels Dec 20, 2023
@MichaReiser MichaReiser changed the base branch from main to fix-avoid-parenthesizing-attribute-chains December 20, 2023 10:30
Copy link
Contributor

github-actions bot commented Dec 20, 2023

ruff-ecosystem results

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

Base automatically changed from fix-avoid-parenthesizing-attribute-chains to main December 20, 2023 23:42
@MichaReiser MichaReiser force-pushed the parenthesize-long-type-annotations-in-annotated-assigns branch 2 times, most recently from 95130ad to d3ce8c9 Compare December 21, 2023 01:58
class Test:
- safe_age: Decimal # the user's age, used to determine if it's safe for them to use ruff
+ safe_age: (
+ Decimal # the user's age, used to determine if it's safe for them to use ruff
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not a huge fan of this change but it is consistent to how we would format the same assignment when Decimalis the assigned value

Input

safe_age = Decimal #  the user's age....

@MichaReiser MichaReiser force-pushed the parenthesize-long-type-annotations-in-annotated-assigns branch 2 times, most recently from 29a97ed to 9ddc579 Compare December 21, 2023 02:10
@MichaReiser MichaReiser marked this pull request as ready for review December 21, 2023 02:21
@MichaReiser MichaReiser force-pushed the parenthesize-long-type-annotations-in-annotated-assigns branch from 9ddc579 to 8e14838 Compare December 21, 2023 23:56
Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

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

Nice, this looks good to me. Thanks for all the clear comments around the intended preview behavior. I wonder if we'd see more ecosystem changes by including the function parameter annotations... maybe?

@MichaReiser
Copy link
Member Author

Nice, this looks good to me. Thanks for all the clear comments around the intended preview behavior. I wonder if we'd see more ecosystem changes by including the function parameter annotations... maybe?

Yeah, there are more changes if you include the function parameters. It's not a ton but a couple of 100 changed lines.

@MichaReiser MichaReiser merged commit fa2c37b into main Dec 22, 2023
17 checks passed
@MichaReiser MichaReiser deleted the parenthesize-long-type-annotations-in-annotated-assigns branch December 22, 2023 03:33
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.

2 participants