# HG changeset patch # User Yuya Nishihara # Date 2018-08-05 03:11:19 # 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 --git a/mercurial/minirst.py b/mercurial/minirst.py --- a/mercurial/minirst.py +++ b/mercurial/minirst.py @@ -673,13 +673,9 @@ def format(text, width=80, indent=0, kee 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 --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py --- a/mercurial/templatefuncs.py +++ b/mercurial/templatefuncs.py @@ -575,7 +575,7 @@ def rstdoc(context, mapping, args): 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 --git a/tests/test-minirst.py b/tests/test-minirst.py --- a/tests/test-minirst.py +++ b/tests/test-minirst.py @@ -7,6 +7,7 @@ from mercurial.utils import ( ) 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 @@ def debugformat(text, form, **kwargs): 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()