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

Formatter: Wrapping Parentheses Different than Black #8268

Closed
juftin opened this issue Oct 27, 2023 · 3 comments
Closed

Formatter: Wrapping Parentheses Different than Black #8268

juftin opened this issue Oct 27, 2023 · 3 comments
Labels
formatter Related to the formatter

Comments

@juftin
Copy link
Contributor

juftin commented Oct 27, 2023

Summary

Black and Ruff formatted this code differently - I don't think this is a Known Deviation and could't find an similar issue.

Both are readable but I actually prefer what black is doing here on YELLOWSTONE_CAMPSITE_AVAILABILITY and YELLOWSTONE_PROPERTY_INFO. I prefer the variable name and the type annotation on the same line as opposed to the variable name, annotation, and value on three separate lines. I also prefer the parentheses to be around the value instead of the annotation.

I came across the issue when moving from black to ruff on a large code base. Everything else looked perfect!

Original Code

class YellowstoneConfig:
    """
    Yellowstone Variable Storage Class
    """

    API_BASE_PATH: str = "v1/api"
    YELLOWSTONE_PARK_PATH: str = "yellowstonenationalparklodges"
    CAMPSITE_AVAILABILITY: str = f"{API_BASE_PATH}/availability/rooms"
    YELLOWSTONE_CAMPSITE_AVAILABILITY: str = f"{CAMPSITE_AVAILABILITY}/{YELLOWSTONE_PARK_PATH}"
    YELLOWSTONE_PROPERTY_INFO: str = f"{API_BASE_PATH}/property/rooms/{YELLOWSTONE_PARK_PATH}"

Code after black

class YellowstoneConfig:
    """
    Yellowstone Variable Storage Class
    """

    API_BASE_PATH: str = "v1/api"
    YELLOWSTONE_PARK_PATH: str = "yellowstonenationalparklodges"
    CAMPSITE_AVAILABILITY: str = f"{API_BASE_PATH}/availability/rooms"
    YELLOWSTONE_CAMPSITE_AVAILABILITY: str = (
        f"{CAMPSITE_AVAILABILITY}/{YELLOWSTONE_PARK_PATH}"
    )
    YELLOWSTONE_PROPERTY_INFO: str = (
        f"{API_BASE_PATH}/property/rooms/{YELLOWSTONE_PARK_PATH}"
    )

Code After ruff format

Note that both the original and the black code will be changed to this

class YellowstoneConfig:
    """
    Yellowstone Variable Storage Class
    """

    API_BASE_PATH: str = "v1/api"
    YELLOWSTONE_PARK_PATH: str = "yellowstonenationalparklodges"
    CAMPSITE_AVAILABILITY: str = f"{API_BASE_PATH}/availability/rooms"
    YELLOWSTONE_CAMPSITE_AVAILABILITY: (
        str
    ) = f"{CAMPSITE_AVAILABILITY}/{YELLOWSTONE_PARK_PATH}"
    YELLOWSTONE_PROPERTY_INFO: (
        str
    ) = f"{API_BASE_PATH}/property/rooms/{YELLOWSTONE_PARK_PATH}"

Settings

  • ruff==0.1.3
  • black==23.3.0
  • Settings: None
@MichaReiser MichaReiser added the formatter Related to the formatter label Oct 27, 2023
@MichaReiser
Copy link
Member

Hey @juftin

I think #8233 should have fixed this and is part of the latest ruff version 0.1.3 (playground).

Can you run ruff version and share the output with us? I'm trying to understand what's going on.

@juftin
Copy link
Contributor Author

juftin commented Oct 27, 2023

🤦 yep, you're right @MichaReiser. I was using my global ruff which was at 0.0.292 instead of my project's ruff (0.1.3). Everything looks perfect now. Really fantastic work.

@juftin juftin closed this as completed Oct 27, 2023
@MichaReiser
Copy link
Member

Perfect. Thanks for reporting back.

@MichaReiser MichaReiser added this to the Formatter: Stable milestone Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter
Projects
None yet
Development

No branches or pull requests

2 participants