[PATCH 5 of 5] byteify-strings: fix alignment issue

Yuya Nishihara yuya at tcha.org
Fri Aug 2 20:41:27 EDT 2019


On Fri, 02 Aug 2019 17:01:26 +0200, Raphaël Gomès wrote:
> # HG changeset patch
> # User Raphaël Gomès <rgomes at octobus.net>
> # Date 1564758059 -7200
> #      Fri Aug 02 17:00:59 2019 +0200
> # Node ID 91da691d3bbc18d32760179e4012047505c244b8
> # Parent  1ae95b109c557785f566d307c13ded3eedc73dd9
> # EXP-Topic byteify-strings
> byteify-strings: fix alignment issue
> 
> While removing this `if` statement fixes the alignment issue, I could not
> figure out what it was intended for despite its comment, and I am hoping its
> author Yuya can help me fix both issues at the same time.
> 
> diff -r 1ae95b109c55 -r 91da691d3bbc contrib/byteify-strings.py
> --- a/contrib/byteify-strings.py	Fri Aug 02 16:57:22 2019 +0200
> +++ b/contrib/byteify-strings.py	Fri Aug 02 17:00:59 2019 +0200
> @@ -134,9 +134,6 @@
>          if coloffset < 0:
>              if t.start[1] == parens[-1][1]:
>                  coloffset = parens[-1][2]
> -            elif t.start[1] + 1 == parens[-1][1]:
> -                # fix misaligned indent of s/util.Abort/error.Abort/
> -                coloffset = parens[-1][2] + (parens[-1][1] - t.start[1])

It handles the following example:

  $ cat > misaligned.py <<'EOF'
  > def foo():
  >     error.Abort(_("foo"
  >                  "bar"
  >                  "%s")
  >                % parameter)
  > EOF
  $ $PYTHON $BINDIR/contrib/byteify-strings.py misaligned.py
  def foo():
      error.Abort(_(b"foo"
                    b"bar"
                    b"%s")
                  % parameter)

Perhaps, we'll need to check the token right after the opening paren. If
the token is whitespace-ish, the paired paren should be at the same column.

    {
    }

If not, it should be at the end column of the opening paren.

    {foo,
     }

Thanks for adding tests.


More information about the Mercurial-devel mailing list