Skip to content

Add note about dict indentation style to docs #925

@strokirk

Description

@strokirk

Hi!

I've been searching a bit on why this code containing a single inline-dict is expanded into multiple lines with hanging braces by black, but couldn't find anything about configuring it, if it's expected, or a bug.

# In
func({
	# expand me
    'a':37,
    'b':42,
    'c':927,
})

# Out
func(
    {
		# expand me
        "a": 37,
        "b": 42,
        "c": 927,
    }
)

I personally would prefer the dict to keep it's original formatting for better readability, and lose the extra indentation and Allman-style hanging bracket. Essentially we would keep the input formatting in this example.

This pattern is also much more common in the python code I regularly read, including the standard library, django and a couple of other codebases. Grepping \({$ vs \(\n\s*{$ shows usages.

However, I expect this pattern might be fairly set in stone by now and would maybe cause a lot of unnecessary diffs for existing black users. What do you think?

Either way, I think something like this would be a useful example to add to the Black code style. That way people like me who are wondering why the function call is expanded can find out that it is to be expected.
(I'm opening this issue partly to be able to google for it myself in coming years.)

Hopefully the feedback is somewhat useful!

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: linebreakHow should we split up lines?T: styleWhat do we want Blackened code to look like?

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions