Patchwork [10,of,10,py3] help: when looking for exclusion kws, convert doc to sysbytes

login
register
mail settings
Submitter Augie Fackler
Date May 29, 2017, 2:32 p.m.
Message ID <6e1f46fb198dbe5ec45d.1496068352@imladris.local>
Download mbox | patch
Permalink /patch/21055/
State Accepted
Headers show

Comments

Augie Fackler - May 29, 2017, 2:32 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1496001043 14400
#      Sun May 28 15:50:43 2017 -0400
# Node ID 6e1f46fb198dbe5ec45d01a34cea43c541bd7233
# Parent  f1be99397daee2fa8bd9d04cb1296cb7e0260c0d
help: when looking for exclusion kws, convert doc to sysbytes

There's one spot where doc is sometimes a unicode - I haven't figured
out when that happens, but it was easy enough to work around that I
just did so.
Yuya Nishihara - May 30, 2017, 12:56 p.m.
On Mon, 29 May 2017 10:32:32 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1496001043 14400
> #      Sun May 28 15:50:43 2017 -0400
> # Node ID 6e1f46fb198dbe5ec45d01a34cea43c541bd7233
> # Parent  f1be99397daee2fa8bd9d04cb1296cb7e0260c0d
> help: when looking for exclusion kws, convert doc to sysbytes
> 
> There's one spot where doc is sometimes a unicode - I haven't figured
> out when that happens, but it was easy enough to work around that I
> just did so.
> 
> diff --git a/mercurial/help.py b/mercurial/help.py
> --- a/mercurial/help.py
> +++ b/mercurial/help.py
> @@ -114,6 +114,8 @@ def indicateomitted(rst, omitted, notomi
>  def filtercmd(ui, cmd, kw, doc):
>      if not ui.debugflag and cmd.startswith("debug") and kw != "debug":
>          return True
> +    if doc and not isinstance(doc, bytes):
> +        doc = pycompat.sysbytes(doc)
>      if not ui.verbose and doc and any(w in doc for w in _exclkeywords):
>          return True
>      return False
> @@ -266,7 +268,8 @@ def makeitemsdoc(ui, topic, doc, marker,
>      for name in sorted(items):
>          text = (items[name].__doc__ or '').rstrip()
>          if (not text
> -            or not ui.verbose and any(w in text for w in _exclkeywords)):
> +            or not ui.verbose
> +            and any(w in pycompat.sysbytes(text) for w in _exclkeywords)):

That's probably because __doc__ is unicode. We'll need to convert every __doc__
back to bytes.
Augie Fackler - May 31, 2017, 7:18 p.m.
> On May 30, 2017, at 08:56, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> On Mon, 29 May 2017 10:32:32 -0400, Augie Fackler wrote:
>> # HG changeset patch
>> # User Augie Fackler <raf@durin42.com>
>> # Date 1496001043 14400
>> #      Sun May 28 15:50:43 2017 -0400
>> # Node ID 6e1f46fb198dbe5ec45d01a34cea43c541bd7233
>> # Parent  f1be99397daee2fa8bd9d04cb1296cb7e0260c0d
>> help: when looking for exclusion kws, convert doc to sysbytes
>> 
>> There's one spot where doc is sometimes a unicode - I haven't figured
>> out when that happens, but it was easy enough to work around that I
>> just did so.
>> 
>> diff --git a/mercurial/help.py b/mercurial/help.py
>> --- a/mercurial/help.py
>> +++ b/mercurial/help.py
>> @@ -114,6 +114,8 @@ def indicateomitted(rst, omitted, notomi
>> def filtercmd(ui, cmd, kw, doc):
>>     if not ui.debugflag and cmd.startswith("debug") and kw != "debug":
>>         return True
>> +    if doc and not isinstance(doc, bytes):
>> +        doc = pycompat.sysbytes(doc)
>>     if not ui.verbose and doc and any(w in doc for w in _exclkeywords):
>>         return True
>>     return False
>> @@ -266,7 +268,8 @@ def makeitemsdoc(ui, topic, doc, marker,
>>     for name in sorted(items):
>>         text = (items[name].__doc__ or '').rstrip()
>>         if (not text
>> -            or not ui.verbose and any(w in text for w in _exclkeywords)):
>> +            or not ui.verbose
>> +            and any(w in pycompat.sysbytes(text) for w in _exclkeywords)):
> 
> That's probably because __doc__ is unicode. We'll need to convert every __doc__
> back to bytes.

Seems likely, but it also has to stay unicode until we're ready to use it for python internals reasons.

Does the approach in this patch seem reasonable-ish?

Patch

diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -114,6 +114,8 @@  def indicateomitted(rst, omitted, notomi
 def filtercmd(ui, cmd, kw, doc):
     if not ui.debugflag and cmd.startswith("debug") and kw != "debug":
         return True
+    if doc and not isinstance(doc, bytes):
+        doc = pycompat.sysbytes(doc)
     if not ui.verbose and doc and any(w in doc for w in _exclkeywords):
         return True
     return False
@@ -266,7 +268,8 @@  def makeitemsdoc(ui, topic, doc, marker,
     for name in sorted(items):
         text = (items[name].__doc__ or '').rstrip()
         if (not text
-            or not ui.verbose and any(w in text for w in _exclkeywords)):
+            or not ui.verbose
+            and any(w in pycompat.sysbytes(text) for w in _exclkeywords)):
             continue
         text = gettext(text)
         if dedent: