Patchwork py3: silence "bad escape" warning emitted by re.sub()

login
register
mail settings
Submitter Yuya Nishihara
Date March 2, 2018, 8:32 p.m.
Message ID <b9a4498025f901cce6a5.1520022737@mimosa>
Download mbox | patch
Permalink /patch/28724/
State Accepted
Headers show

Comments

Yuya Nishihara - March 2, 2018, 8:32 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1519946556 18000
#      Thu Mar 01 18:22:36 2018 -0500
# Node ID b9a4498025f901cce6a5ceaedf027173e11d6a59
# Parent  dfcf589a4031211a67bab022e0a1b414f364bc39
py3: silence "bad escape" warning emitted by re.sub()

Since we pass user strings directly to re.sub(), we can't avoid this warning
without a BC.
Gregory Szorc - March 2, 2018, 8:45 p.m.
On Fri, Mar 2, 2018 at 3:32 PM, Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1519946556 18000
> #      Thu Mar 01 18:22:36 2018 -0500
> # Node ID b9a4498025f901cce6a5ceaedf027173e11d6a59
> # Parent  dfcf589a4031211a67bab022e0a1b414f364bc39
> py3: silence "bad escape" warning emitted by re.sub()
>

Queued, thanks.


>
> Since we pass user strings directly to re.sub(), we can't avoid this
> warning
> without a BC.
>
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -246,6 +246,10 @@ if _dowarn:
>      warnings.filterwarnings(r'default', r'', DeprecationWarning,
> r'mercurial')
>      warnings.filterwarnings(r'default', r'', DeprecationWarning,
> r'hgext')
>      warnings.filterwarnings(r'default', r'', DeprecationWarning,
> r'hgext3rd')
> +if _dowarn and pycompat.ispy3:
> +    # silence warning emitted by passing user string to re.sub()
> +    warnings.filterwarnings(r'ignore', r'bad escape', DeprecationWarning,
> +                            r'mercurial')
>
>  def nouideprecwarn(msg, version, stacklevel=1):
>      """Issue an python native deprecation warning
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -246,6 +246,10 @@  if _dowarn:
     warnings.filterwarnings(r'default', r'', DeprecationWarning, r'mercurial')
     warnings.filterwarnings(r'default', r'', DeprecationWarning, r'hgext')
     warnings.filterwarnings(r'default', r'', DeprecationWarning, r'hgext3rd')
+if _dowarn and pycompat.ispy3:
+    # silence warning emitted by passing user string to re.sub()
+    warnings.filterwarnings(r'ignore', r'bad escape', DeprecationWarning,
+                            r'mercurial')
 
 def nouideprecwarn(msg, version, stacklevel=1):
     """Issue an python native deprecation warning