[PATCH 6 of 7] minirst: make format() simply return a formatted text
Yuya Nishihara
yuya at tcha.org
Wed Aug 22 08:19:54 EDT 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1533438679 -32400
# Sun Aug 05 12:11:19 2018 +0900
# Node ID 2aa41bb00b93fd9cc5459aef6bd83d0b3ba77ab3
# Parent 7ba0774e0bbdb9ed5b87a9e27bef443adab09c85
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()
More information about the Mercurial-devel
mailing list