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: % formatting in dictionary keys #6974

Closed
MichaReiser opened this issue Aug 29, 2023 · 1 comment
Closed

Formatter: % formatting in dictionary keys #6974

MichaReiser opened this issue Aug 29, 2023 · 1 comment
Labels
formatter Related to the formatter

Comments

@MichaReiser
Copy link
Member

MichaReiser commented Aug 29, 2023

Black breaks dictionary entries after the % even if the key otherwise would fit:

obj = (
    self.__class__._default_manager.filter(**filter_args)
    .filter(
        **{
            "_order__%s"
            % op: self.__class__._default_manager.values("_order").filter(
                **{self._meta.pk.name: self.pk}
            )
        }
    )
    .order_by(order)[:1]
    .get()
)


def test():
    if True:
        qs = GeoColumn.objects.filter(
            **{
                "%s__in"
                % GeoColumn.table_name_col(): ["gis_neighborhood", "gis_household"]
            }
        )

IMO, this is very difficult to parse and probably just a fallout of their implementation that inserts line breaks after the highest priority operator, which happens to be the % in these cases.

Ruff tries to keep the key on its own line and instead breaks the value:

obj = (
    self.__class__._default_manager.filter(**filter_args)
    .filter(
        **{
            "_order__%s" % op: self.__class__._default_manager.values("_order").filter(
                **{self._meta.pk.name: self.pk}
            )
        }
    )
    .order_by(order)[:1]
    .get()
)


def test():
    if True:
        qs = GeoColumn.objects.filter(
            **{
                "%s__in" % GeoColumn.table_name_col(): [
                    "gis_neighborhood",
                    "gis_household",
                ]
            }
        )

IMO, this is more readable.

#6069

@MichaReiser MichaReiser added the formatter Related to the formatter label Aug 29, 2023
@MichaReiser
Copy link
Member Author

Closing because Ruff's formatting is more readable and implementing Black's behavior requires special casing.

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

1 participant