# HG changeset patch # User Yuya Nishihara # Date 1533438679 -32400 # Node ID a2a5d4ad5276a3d400dc32e744e70614554bde49 # Parent 0a766cb1092a2d798e44c008cb3989f653a01c0b minirst: make format() simply return a formatted text It's a source of bugs to change the type of the return value conditionally. diff -r 0a766cb1092a -r a2a5d4ad5276 mercurial/minirst.py --- a/mercurial/minirst.py Sun Aug 05 12:20:43 2018 +0900 +++ b/mercurial/minirst.py Sun Aug 05 12:11:19 2018 +0900 @@ -673,13 +673,9 @@ if section: blocks = filtersections(blocks, section) if style == 'html': - text = formathtml(blocks) + return formathtml(blocks) else: - text = formatplain(blocks, width=width) - if keep is None: - return text - else: - return text, pruned + return formatplain(blocks, width=width) def filtersections(blocks, section): """Select parsed blocks under the specified section""" diff -r 0a766cb1092a -r a2a5d4ad5276 mercurial/templatefuncs.py --- a/mercurial/templatefuncs.py Sun Aug 05 12:20:43 2018 +0900 +++ b/mercurial/templatefuncs.py Sun Aug 05 12:11:19 2018 +0900 @@ -575,7 +575,7 @@ text = evalstring(context, mapping, args[0]) style = evalstring(context, mapping, args[1]) - return minirst.format(text, style=style, keep=['verbose'])[0] + return minirst.format(text, style=style, keep=['verbose']) @templatefunc('separate(sep, args...)', argspec='sep *args') def separate(context, mapping, args): diff -r 0a766cb1092a -r a2a5d4ad5276 tests/test-minirst.py --- a/tests/test-minirst.py Sun Aug 05 12:20:43 2018 +0900 +++ b/tests/test-minirst.py Sun Aug 05 12:11:19 2018 +0900 @@ -7,6 +7,7 @@ ) def debugformat(text, form, **kwargs): + blocks, pruned = minirst.parse(text, **kwargs) if form == b'html': print("html format:") out = minirst.format(text, style=form, **kwargs) @@ -15,12 +16,10 @@ out = minirst.format(text, width=form, **kwargs) print("-" * 70) - if type(out) == tuple: - print(out[0][:-1].decode('utf8')) + print(out[:-1].decode('utf8')) + if kwargs.get('keep'): print("-" * 70) - print(stringutil.pprint(out[1]).decode('utf8')) - else: - print(out[:-1].decode('utf8')) + print(stringutil.pprint(pruned).decode('utf8')) print("-" * 70) print()