Patchwork [5,of,5] byteify-strings: fix alignment issue

login
register
mail settings
Submitter Raphaël Gomès
Date Aug. 2, 2019, 3:01 p.m.
Message ID <91da691d3bbc18d32760.1564758086@alphare-carbon.lan>
Download mbox | patch
Permalink /patch/41132/
State Accepted
Headers show

Comments

Raphaël Gomès - Aug. 2, 2019, 3:01 p.m.
# HG changeset patch
# User Raphaël Gomès <rgomes@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.
Yuya Nishihara - Aug. 3, 2019, 12:41 a.m.
On Fri, 02 Aug 2019 17:01:26 +0200, Raphaël Gomès wrote:
> # HG changeset patch
> # User Raphaël Gomès <rgomes@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.

Patch

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])
             else:
                 coloffset = 0
 
diff -r 1ae95b109c55 -r 91da691d3bbc tests/test-byteify-strings.t
--- a/tests/test-byteify-strings.t	Fri Aug 02 16:57:22 2019 +0200
+++ b/tests/test-byteify-strings.t	Fri Aug 02 17:00:59 2019 +0200
@@ -216,6 +216,6 @@ 
           (b'a', b'b'),
           {
               b'aslkdjf',
-           }
-       ]
+          }
+      ]
   )