Patchwork hgmanpage: stop using raw-unicode strings

login
register
mail settings
Submitter Augie Fackler
Date Oct. 7, 2016, 11:43 a.m.
Message ID <cd328294e99652c9b295.1475840609@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/16871/
State Accepted
Headers show

Comments

Augie Fackler - Oct. 7, 2016, 11:43 a.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1475840584 14400
#      Fri Oct 07 07:43:04 2016 -0400
# Node ID cd328294e99652c9b295c1e343a753384cbdc468
# Parent  f18cc848b48e2de5536fc861007d78d7d5bae42b
hgmanpage: stop using raw-unicode strings

These don't exist in Python 3, and this ends up looking a little more
explicit to Martijn and me anyway.
Martijn Pieters - Oct. 7, 2016, 11:58 a.m.
On 7 October 2016 at 13:43, Augie Fackler <raf@durin42.com> wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1475840584 14400
> #      Fri Oct 07 07:43:04 2016 -0400
> # Node ID cd328294e99652c9b295c1e343a753384cbdc468
> # Parent  f18cc848b48e2de5536fc861007d78d7d5bae42b
> hgmanpage: stop using raw-unicode strings
>
> These don't exist in Python 3, and this ends up looking a little more
> explicit to Martijn and me anyway.

Yup, since this makes it far more explicit that those backslashes are
raw backslashes and not an attempt at producing regexes, which was my
first reaction.

And to make it explicit and not just Augie namedropping: Looks good to me.

> diff --git a/doc/hgmanpage.py b/doc/hgmanpage.py
> --- a/doc/hgmanpage.py
> +++ b/doc/hgmanpage.py
> @@ -288,10 +288,10 @@ class Translator(nodes.NodeVisitor):
>          text = node.astext()
>          text = text.replace('\\','\\e')
>          replace_pairs = [
> -            (u'-', ur'\-'),
> -            (u'\'', ur'\(aq'),
> -            (u'´', ur'\''),
> -            (u'`', ur'\(ga'),
> +            (u'-', u'\\-'),
> +            (u"'", u'\\(aq'),
> +            (u'´', u"\\'"),
> +            (u'`', u'\\(ga'),
>              ]
>          for (in_char, out_markup) in replace_pairs:
>              text = text.replace(in_char, out_markup)
> diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t
> --- a/tests/test-check-py3-compat.t
> +++ b/tests/test-check-py3-compat.t
> @@ -16,7 +16,6 @@
>    $ hg files 'set:(**.py) - grep(pygments)' | sed 's|\\|/|g' \
>    > | xargs $PYTHON3 contrib/check-py3-compat.py \
>    > | sed 's/[0-9][0-9]*)$/*)/'
> -  doc/hgmanpage.py: invalid syntax: invalid syntax (<unknown>, line *)
>    hgext/acl.py: error importing: <TypeError> Can't mix strings and bytes in path components (error at i18n.py:*)
>    hgext/automv.py: error importing: <TypeError> Can't mix strings and bytes in path components (error at i18n.py:*)
>    hgext/blackbox.py: error importing: <TypeError> Can't mix strings and bytes in path components (error at i18n.py:*)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Yuya Nishihara - Oct. 8, 2016, 6:58 a.m.
On Fri, 07 Oct 2016 07:43:29 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1475840584 14400
> #      Fri Oct 07 07:43:04 2016 -0400
> # Node ID cd328294e99652c9b295c1e343a753384cbdc468
> # Parent  f18cc848b48e2de5536fc861007d78d7d5bae42b
> hgmanpage: stop using raw-unicode strings
> 
> These don't exist in Python 3, and this ends up looking a little more
> explicit to Martijn and me anyway.

Queued, thanks.

Patch

diff --git a/doc/hgmanpage.py b/doc/hgmanpage.py
--- a/doc/hgmanpage.py
+++ b/doc/hgmanpage.py
@@ -288,10 +288,10 @@  class Translator(nodes.NodeVisitor):
         text = node.astext()
         text = text.replace('\\','\\e')
         replace_pairs = [
-            (u'-', ur'\-'),
-            (u'\'', ur'\(aq'),
-            (u'´', ur'\''),
-            (u'`', ur'\(ga'),
+            (u'-', u'\\-'),
+            (u"'", u'\\(aq'),
+            (u'´', u"\\'"),
+            (u'`', u'\\(ga'),
             ]
         for (in_char, out_markup) in replace_pairs:
             text = text.replace(in_char, out_markup)
diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t
+++ b/tests/test-check-py3-compat.t
@@ -16,7 +16,6 @@ 
   $ hg files 'set:(**.py) - grep(pygments)' | sed 's|\\|/|g' \
   > | xargs $PYTHON3 contrib/check-py3-compat.py \
   > | sed 's/[0-9][0-9]*)$/*)/'
-  doc/hgmanpage.py: invalid syntax: invalid syntax (<unknown>, line *)
   hgext/acl.py: error importing: <TypeError> Can't mix strings and bytes in path components (error at i18n.py:*)
   hgext/automv.py: error importing: <TypeError> Can't mix strings and bytes in path components (error at i18n.py:*)
   hgext/blackbox.py: error importing: <TypeError> Can't mix strings and bytes in path components (error at i18n.py:*)