Display (None) instead of a bullet for empty lists (#5999)

Include a line break before "(None)" to maintain consistency with output
for lists that are not empty.

Previous result as expected for non-empty lists:

    >>> _format_list('+', ['one', 'two', 'three'])
    '\n+ one\n+ two\n+ three'

Previous unexpected result for empty lists:

    >>> _format_list('+', [])
    '\n+ '

New result as expected (unchanged) for non-empty lists:

    >>> _format_list('+', ['one', 'two', 'three'])
    '\n+ one\n+ two\n+ three'

New behavior more explicit for empty lists:

    >>> _format_list('+', [])
    '\n(None)'

Resolves #5886
This commit is contained in:
Douglas Anger 2018-05-15 11:46:36 -04:00 committed by Brad Warren
parent 42ef252043
commit 2d68c9b81e

View file

@ -340,7 +340,10 @@ def _get_added_removed(after, before):
def _format_list(character, strings):
"""Format list with given character
"""
formatted = "{br}{ch} " + "{br}{ch} ".join(strings)
if len(strings) == 0:
formatted = "{br}(None)"
else:
formatted = "{br}{ch} " + "{br}{ch} ".join(strings)
return formatted.format(
ch=character,
br=os.linesep