Patchwork [1,of,6] py3: use startswith() instead of slicing to detect leading whitespace

login
register
mail settings
Submitter Yuya Nishihara
Date March 4, 2018, 9:41 p.m.
Message ID <f7cd53c5127f248f5d07.1520199696@mimosa>
Download mbox | patch
Permalink /patch/29002/
State Accepted
Headers show

Comments

Yuya Nishihara - March 4, 2018, 9:41 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1520195085 18000
#      Sun Mar 04 15:24:45 2018 -0500
# Node ID f7cd53c5127f248f5d075ad28b6be82558b7c35d
# Parent  6bacb2f663cb07f58bb493db5f21ae321d5a2e06
py3: use startswith() instead of slicing to detect leading whitespace
Pulkit Goyal - March 4, 2018, 9:47 p.m.
Queued the series. Many thanks!

On Mon, Mar 5, 2018 at 3:11 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1520195085 18000
> #      Sun Mar 04 15:24:45 2018 -0500
> # Node ID f7cd53c5127f248f5d075ad28b6be82558b7c35d
> # Parent  6bacb2f663cb07f58bb493db5f21ae321d5a2e06
> py3: use startswith() instead of slicing to detect leading whitespace
>
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -158,7 +158,7 @@ def _formatparse(write, inst):
>      if len(inst.args) > 1:
>          write(_("hg: parse error at %s: %s\n") %
>                (pycompat.bytestr(inst.args[1]), inst.args[0]))
> -        if (inst.args[0][0] == ' '):
> +        if inst.args[0].startswith(' '):
>              write(_("unexpected leading whitespace\n"))
>      else:
>          write(_("hg: parse error: %s\n") % inst.args[0])
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -158,7 +158,7 @@  def _formatparse(write, inst):
     if len(inst.args) > 1:
         write(_("hg: parse error at %s: %s\n") %
               (pycompat.bytestr(inst.args[1]), inst.args[0]))
-        if (inst.args[0][0] == ' '):
+        if inst.args[0].startswith(' '):
             write(_("unexpected leading whitespace\n"))
     else:
         write(_("hg: parse error: %s\n") % inst.args[0])