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

Indentation of split string in dict would be better align to the value rather than key #3857

Closed
masterspelling opened this issue Aug 30, 2023 · 4 comments
Labels
T: bug Something isn't working

Comments

@masterspelling
Copy link

masterspelling commented Aug 30, 2023

Describe the bug
Indentation of split string in dict would be better align to the value rather than key

To Reproduce

For example, take this code:

a_dict = {
    "key1": "value1",
    "key2": "long longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong"
       "long long value",
}

Expected behavior

I think it would be visually more pleasing to have it aligned by value

a_dict = {
    "key1": "value1",
    "key2": "long longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong"
            "long long value",
}

currently it is aligns it by key

a_dict = {
    "key1": "value1",
    "key2": "long longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong"
    "long long value",
}
@masterspelling masterspelling added the T: bug Something isn't working label Aug 30, 2023
@jakkdl
Copy link
Contributor

jakkdl commented Sep 26, 2023

getting it aligned by the value sounds messy, given the length of the key may differ greatly - and esp if the length of the key is very long it makes it incredibly messy

a dict = {
    my_function_call(arg1, arg2, arg3, 300 + 25 * 99): "long longlonglonglonglonglonglonglong"
                                                       "long long value",
    my_function_call(arg1, arg2, arg3): "long longlonglonglonglonglonglonglong"
                                        "long long value",
}

It should probably get wrapped in parentheses (easy to implement, something similar to #3899) or get indented one step further in though:

a_dict = {
    "key1": "value1",
    "key2": "long longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong"
        "long long value",
    "key3": (
        "long longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong"
        "long long value"
    ),
}

@JelleZijlstra
Copy link
Collaborator

We should use the parenthesized version. This follows the principle in Black that indentation should always be a multiple of four.

@Shreya-7
Copy link
Contributor

Shreya-7 commented Oct 2, 2023

Happy to take a stab at this!

@JelleZijlstra
Copy link
Collaborator

Current preview style adds parentheses:

% black --preview -c '''a_dict = {
    "key1": "value1",
    "key2": "long longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong"
       "long long value",
}
'''
a_dict = {
    "key1": "value1",
    "key2": (
        "long longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong"
        " long value"
    ),
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants