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

PEP8: Dictionary values should have an extra indent #113

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions pep-0008.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,51 @@ Optional::
var_one, var_two,
var_three, var_four)

For dictionaries there is an extra rule. When placing a dictionary key on a new
Copy link
Member

@Mariatta Mariatta Oct 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicky 😅 there should be a comma
For dictionaries, there is ...

... on a new line, an additional ...

line an additional hanging indent should be added. This is so it is easy to
differentiate between keys and values.

Yes::

# Keys aligned with opening delimiter, values have an extra indent.
mydict = {'firstkey':
'a very very very very very long value',
'secondkey': 'a short value',
'thirdkey': 'a very very very'
' long value that continues on the next line'
' and even on the line after that.',
}

# Keys with one and values with two levels of hanging indents.
mydict = {
'firstkey':
'a very very very very very long value',
'secondkey': 'a short value',
'thirdkey': 'a very very very'
Copy link
Member

@Mariatta Mariatta Oct 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to share what other IDE is already doing with respect to this issue.

PyCharm will automatically do this for you

'thirdkey':
    'a very very very'
    'long value that continues on the next line'
    'and even on the line after that.',

And this too

'thirdkey': 'a very very very'
            'long value that continues on the next line'
            'and even on the line after that.',

But it will not do this one, which is being considered as a 'yes' in this proposal.

'thirdkey': 'a very very very'
    'long value that continues on the next line'
    'and even on the line after that.',

Perhaps something to take into account when making decision about this.
Thanks :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the option is not done by pycharm the least as well, but I didn't want to make the change to opinionated.

' long value that continues on the next line'
' and even on the line after that.',
}

# Continuing value indented to column where the value starts.
mydict = {
'thirdkey': 'a very very very'
' long value that continues on the next line'
' and even on the line after that.',
}


No::

# Keys and values indented in the same way.
mydict = {'firstkey':
'a very very very very very long value',
'secondkey': 'a short value',
'thirdkey': 'a very very very'
' long value that continues on the next line',
' and even on the line after that.'
}


.. _`multiline if-statements`:

When the conditional part of an ``if``-statement is long enough to require
Expand Down