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

Black inconsistent about arguments with many alternative types #2767

Closed
Illviljan opened this issue Jan 12, 2022 · 2 comments
Closed

Black inconsistent about arguments with many alternative types #2767

Illviljan opened this issue Jan 12, 2022 · 2 comments
Labels
F: linebreak How should we split up lines? T: style What do we want Blackened code to look like?

Comments

@Illviljan
Copy link

Illviljan commented Jan 12, 2022

Describe the style change
Black is not consistent when arguments can be many types.

This is the original format, both stat_lengthh and stat_lengths have the same typing but one has parenthesis around it:

from __future__ import annotations

from typing import Any, Mapping


class test:
    def pad(
        self,
        stat_lengthh: (int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None) = None,
        stat_lengths: int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None = None,
    ):
        pass

Examples in the current Black style

Black formats the same typing in two different ways making it hard to see they are exactly the same:

from __future__ import annotations

from typing import Any, Mapping


class test:
    def pad(
        self,
        stat_lengthh: (
            int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None
        ) = None,
        stat_lengths: int
        | tuple[int, int]
        | Mapping[Any, tuple[int, int]]
        | None = None,
    ):
        pass

Desired style
I prefer the variant with parenthesis, the extra indent makes it easier to tell where the new arguments are.

from __future__ import annotations

from typing import Any, Mapping


class test:
    def pad(
        self,
        stat_lengthh: (
            int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None
        ) = None,
        stat_lengths: (
            int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None
        ) = None,
    ):
        pass

Additional context

@Illviljan Illviljan added the T: style What do we want Blackened code to look like? label Jan 12, 2022
@felix-hilden felix-hilden added the F: linebreak How should we split up lines? label Jan 12, 2022
@felix-hilden
Copy link
Collaborator

All for the consistency, but personally I'm not sure which style would be better. Thanks for reporting!

@JelleZijlstra
Copy link
Collaborator

I also prefer the parenthesized version, since it makes it easier to see where each new parameter starts.

Anyway, this is a duplicate of #2316.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linebreak How should we split up lines? T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

3 participants