[Python-ideas] PEP8 dictionary indenting addition
Terry Reedy
tjreedy at udel.edu
Tue Oct 11 22:24:47 EDT 2016
On 10/11/2016 12:08 PM, Ryan Gonzalez wrote:
> On Oct 11, 2016 10:40 AM, "Erik Bray"
> <erik.m.bray at gmail.com
> <mailto:erik.m.bray at gmail.com>> wrote:
>>
>> On Sun, Oct 9, 2016 at 2:25 AM, Steven D'Aprano
> <steve at pearwood.info
> <mailto:steve at pearwood.info>> wrote:
>> > On Sat, Oct 08, 2016 at 09:26:13PM +0200, Jelte Fennema wrote:
>> >> I have an idea to improve indenting guidelines for dictionaries for
> better
>> >> readability: If a value in a dictionary literal is placed on a new
> line, it
>> >> should have (or at least be allowed to have) a n additional hanging
> indent.
>> >>
>> >> Below is an example:
>> >>
>> >> mydict = {'mykey':
>> >> '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',
>> >> }
>> >
>> > Looks good to me, except that my personal preference for the implicit
>> > string concatenation (thirdkey) is to move the space to the
>> > following line, and (if possible) align the parts:
>> > mydict = {'mykey':
>> > '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',
>> > }
>>
>> Heh--not to bikeshed, but my personal preference is to leave the
>> trailing space on the first line. This is because by the time I've
>> started a new line (and possibly have spent time fussing with
>> indentation for the odd cases that my editor doesn't get quite right)
>> I'll have forgotten that I need to start the line with a space :)
I agree that the first version of the example, with space after 'very',
before the quote, is better. I also put '\n' at the end of literals to
be auto-joined, rather than at the beginning.
> Until you end up with like 20 merge conflicts because some editors strip
> trailing whitespace...
A space within a string literal is not trailing whitespace and will not
be stripped.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list