GNU bug report logs - #20742
24.5; python mode indentation fails pep8

Previous Next

Package: emacs;

Reported by: Tommi Komulainen <tommi.komulainen <at> iki.fi>

Date: Fri, 5 Jun 2015 15:22:02 UTC

Severity: normal

Tags: fixed, patch

Merged with 19906

Found in version 24.5

Fixed in version 27.1

Done: Noam Postavsky <npostavs <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 20742 in the body.
You can then email your comments to 20742 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#20742; Package emacs. (Fri, 05 Jun 2015 15:22:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tommi Komulainen <tommi.komulainen <at> iki.fi>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 05 Jun 2015 15:22:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tommi Komulainen <tommi.komulainen <at> iki.fi>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.5; python mode indentation fails pep8
Date: Fri, 5 Jun 2015 09:58:30 +0200
The automatic indentation and manual reindenting with
indent-according-to-mode puts the closing bracket in wrong place that
makes pep8/flake8 flycheck complain:

print("hello",
      "world",
)
E124 closing bracket does not match visual indentation

The bracket needs to align with the first thing after the opening
bracket if it's on the same line i.e.:

print("hello",
      "world",
      )

The automatic indentation doesn't cause any errors if there's a newline
after the opening bracket though:

print(
    "hello",
    "world",
)



In GNU Emacs 24.5.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.16.2)
 of 2015-04-22 on buildhw-10.phx2.fedoraproject.org
Windowing system distributor `Fedora Project', version 11.0.11701000
System Description: Fedora release 22 (Twenty Two)

Configured using:
 `configure --build=x86_64-redhat-linux-gnu
 --host=x86_64-redhat-linux-gnu --program-prefix=
 --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr
 --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc
 --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64
 --libexecdir=/usr/libexec --localstatedir=/var
 --sharedstatedir=/var/lib --mandir=/usr/share/man
 --infodir=/usr/share/info --with-dbus --with-gif --with-jpeg --with-png
 --with-rsvg --with-tiff --with-xft --with-xpm --with-x-toolkit=gtk3
 --with-gpm=no build_alias=x86_64-redhat-linux-gnu
 host_alias=x86_64-redhat-linux-gnu 'CFLAGS=-DMAIL_USE_LOCKF -O2 -g
 -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4
 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1
 -m64 -mtune=generic' LDFLAGS=-Wl,-z,relro'

Important settings:
  value of $LANG: en_US.utf8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Python

Minor modes in effect:
  tooltip-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
(New file)
Can't guess python-indent-offset, using defaults: 4
python-indent--calculate-indentation: Wrong type argument:
number-or-marker-p, nil [2 times]
Making completion list...
python-indent--calculate-indentation: Wrong type argument:
number-or-marker-p, nil [2 times]
Making completion list...
user-error: End of history; no default available [2 times]
Making completion list...

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
help-fns mail-prsvr mail-utils help-mode python easymenu json comint
ring cl-loaddefs cl-lib ansi-color time-date tooltip electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list newcomment lisp-mode
prog-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
minibuffer nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
dbusbind gfilenotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs)

Memory information:
((conses 16 81480 5832)
 (symbols 48 18574 0)
 (miscs 40 39 124)
 (strings 32 12163 4670)
 (string-bytes 1 364259)
 (vectors 16 10283)
 (vector-slots 8 394463 9319)
 (floats 8 66 386)
 (intervals 56 243 1)
 (buffers 960 13)
 (heap 1024 32872 1101))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20742; Package emacs. (Fri, 05 Jun 2015 20:17:02 GMT) Full text and rfc822 format available.

Message #8 received at 20742 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Tommi Komulainen <tommi.komulainen <at> iki.fi>
Cc: 20742 <at> debbugs.gnu.org
Subject: Re: bug#20742: 24.5; python mode indentation fails pep8
Date: Fri, 05 Jun 2015 16:16:41 -0400
Tommi Komulainen wrote:

> python-indent--calculate-indentation: Wrong type argument:
> number-or-marker-p, nil [2 times]

Perhaps the behaviour is not intended.
(Related to bug#20560?)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20742; Package emacs. (Fri, 05 Jun 2015 20:27:02 GMT) Full text and rfc822 format available.

Message #11 received at 20742 <at> debbugs.gnu.org (full text, mbox):

From: Tommi Komulainen <tommi.komulainen <at> iki.fi>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 20742 <at> debbugs.gnu.org
Subject: Re: bug#20742: 24.5; python mode indentation fails pep8
Date: Fri, 05 Jun 2015 20:25:54 +0000
[Message part 1 (text/plain, inline)]
That's almost certainly me having the cursor after the closing bracket
rather than on top of it while double-checking the indentation on each
line. Best I can tell it made no difference to the indentation.

The other bug is closely related when the opening bracket is *not* followed
by newline, though I can't immediately say if either of the possible
indentations is preferred or an error according to pep8.

On Fri, 5 Jun 2015 at 22:16 Glenn Morris <rgm <at> gnu.org> wrote:

> Tommi Komulainen wrote:
>
> > python-indent--calculate-indentation: Wrong type argument:
> > number-or-marker-p, nil [2 times]
>
> Perhaps the behaviour is not intended.
> (Related to bug#20560?)
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20742; Package emacs. (Mon, 08 Jun 2015 16:32:02 GMT) Full text and rfc822 format available.

Message #14 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#20742: 24.5; python mode indentation fails pep8
Date: Mon, 08 Jun 2015 18:28:33 +0200
Am 05.06.2015 um 09:58 schrieb Tommi Komulainen:

May confirm that bug

GNU Emacs 25.0.50.1 (i686-pc-linux-gnu, GTK+ Version 2.24.23) of 2015-06-07




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20742; Package emacs. (Fri, 19 Jun 2015 17:05:03 GMT) Full text and rfc822 format available.

Message #17 received at 20742 <at> debbugs.gnu.org (full text, mbox):

From: Tommi Komulainen <tommi.komulainen <at> iki.fi>
To: "20742 <at> debbugs.gnu.org" <20742 <at> debbugs.gnu.org>
Subject: Testcase for #20742
Date: Fri, 19 Jun 2015 17:04:07 +0000
[Message part 1 (text/plain, inline)]
Patch against emacs-24.5 branch to update the tests to check the closing
paren indentation as well.
[Message part 2 (text/html, inline)]
[0001-update-python-tests.el-for-pep8-indentation.patch (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20742; Package emacs. (Sat, 20 Jun 2015 10:57:01 GMT) Full text and rfc822 format available.

Message #20 received at 20742 <at> debbugs.gnu.org (full text, mbox):

From: Tommi Komulainen <tommi.komulainen <at> iki.fi>
To: 20742 <at> debbugs.gnu.org
Subject: 24.5; [PATCH] python.el: fix close paren indentation to match pep8
Date: Sat, 20 Jun 2015 12:56:40 +0200
From da684af7265bf40e4140328c36011fea6b040373 Mon Sep 17 00:00:00 2001
From: Tommi Komulainen <tommi.komulainen <at> iki.fi>
Date: Fri, 19 Jun 2015 18:53:52 +0200
Subject: [PATCH] python.el: fix close paren indentation to match pep8

When opening paren is followed by newline the closing paren should follow
the current indentation. Otherwise the closing paren should be aligned
with the opening paren. This fixes the latter case. #20742
---
 lisp/progmodes/python.el       | 12 +++++++++---
 test/automated/python-tests.el | 42 +++++++++++++++++++++++++++++++++---------
 2 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index de2d2d1..013a565 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -952,12 +952,18 @@ possibilities can be narrowed to specific
indentation points."
         (`(,(or :after-line
                 :after-comment
                 :inside-string
-                :after-backslash
-                :inside-paren-at-closing-paren
-                :inside-paren-at-closing-nested-paren) . ,start)
+                :after-backslash) . ,start)
          ;; Copy previous indentation.
          (goto-char start)
          (current-indentation))
+        (`(,(or :inside-paren-at-closing-paren
+                :inside-paren-at-closing-nested-paren) . ,start)
+         (goto-char (+ 1 start))
+         (if (looking-at "[ \t]*\\(?:#\\|$\\)")
+             ;; Copy previous indentation.
+             (current-indentation)
+           ;; Align with opening paren.
+           (current-column)))
         (`(,(or :after-block-start
                 :after-backslash-first-line
                 :inside-paren-newline-start) . ,start)
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el
index 42c26fc..f35f188 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -171,16 +171,28 @@ aliqua."
   "First pep8 case."
   (python-tests-with-temp-buffer
    "# Aligned with opening delimiter
-foo = long_function_name(var_one, var_two,
-                         var_three, var_four)
+foo = long_function_name(var_one=[var_two,  # comment
+                                  var_three
+                                  ],
+                         var_four=0,
+                         )
 "
    (should (eq (car (python-indent-context)) :no-indent))
    (should (= (python-indent-calculate-indentation) 0))
-   (python-tests-look-at "foo = long_function_name(var_one, var_two,")
+   (python-tests-look-at "foo = long_function_name(var_one")
    (should (eq (car (python-indent-context)) :after-comment))
    (should (= (python-indent-calculate-indentation) 0))
-   (python-tests-look-at "var_three, var_four)")
+   (python-tests-look-at "var_three")
    (should (eq (car (python-indent-context)) :inside-paren))
+   (should (= (python-indent-calculate-indentation) 34))
+   (python-tests-look-at "]")
+   (should (eq (car (python-indent-context))
:inside-paren-at-closing-nested-paren))
+   (should (= (python-indent-calculate-indentation) 34))
+   (python-tests-look-at "var_four")
+   (should (eq (car (python-indent-context)) :inside-paren))
+   (should (= (python-indent-calculate-indentation) 25))
+   (python-tests-look-at ")")
+   (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren))
    (should (= (python-indent-calculate-indentation) 25))))

 (ert-deftest python-indent-pep8-2 ()
@@ -215,20 +227,32 @@ def long_function_name(
   (python-tests-with-temp-buffer
    "# Extra indentation is not necessary.
 foo = long_function_name(
-  var_one, var_two,
-  var_three, var_four)
+    var_one, var_two=[  # comment
+        var_three,
+    ],
+    var_four=0,
+)
 "
    (should (eq (car (python-indent-context)) :no-indent))
    (should (= (python-indent-calculate-indentation) 0))
    (python-tests-look-at "foo = long_function_name(")
    (should (eq (car (python-indent-context)) :after-comment))
    (should (= (python-indent-calculate-indentation) 0))
-   (python-tests-look-at "var_one, var_two,")
+   (python-tests-look-at "var_one")
    (should (eq (car (python-indent-context)) :inside-paren-newline-start))
    (should (= (python-indent-calculate-indentation) 4))
-   (python-tests-look-at "var_three, var_four)")
+   (python-tests-look-at "var_three")
    (should (eq (car (python-indent-context)) :inside-paren-newline-start))
-   (should (= (python-indent-calculate-indentation) 4))))
+   (should (= (python-indent-calculate-indentation) 8))
+   (python-tests-look-at "]")
+   (should (eq (car (python-indent-context))
:inside-paren-at-closing-nested-paren))
+   (should (= (python-indent-calculate-indentation) 4))
+   (python-tests-look-at "var_four")
+   (should (eq (car (python-indent-context)) :inside-paren-newline-start))
+   (should (= (python-indent-calculate-indentation) 4))
+   (python-tests-look-at ")")
+   (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren))
+   (should (= (python-indent-calculate-indentation) 0))))

 (ert-deftest python-indent-base-case ()
   "Check base case does not trigger errors."
-- 
2.4.4




Merged 19906 20742. Request was from fgallina <at> gnu.org (Fabián Ezequiel Gallina) to control <at> debbugs.gnu.org. (Mon, 06 Jul 2015 02:17:02 GMT) Full text and rfc822 format available.

Merged 19906 20560 20742. Request was from fgallina <at> gnu.org (Fabián Ezequiel Gallina) to control <at> debbugs.gnu.org. (Mon, 06 Jul 2015 02:25:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20742; Package emacs. (Thu, 02 Mar 2017 02:47:01 GMT) Full text and rfc822 format available.

Message #27 received at 20742 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Tommi Komulainen <tommi.komulainen <at> iki.fi>
Cc: 20742 <at> debbugs.gnu.org
Subject: Re: bug#20742: 24.5;
 [PATCH] python.el: fix close paren indentation to match pep8
Date: Wed, 01 Mar 2017 21:47:11 -0500
Tommi Komulainen <tommi.komulainen <at> iki.fi> writes:

>>From da684af7265bf40e4140328c36011fea6b040373 Mon Sep 17 00:00:00 2001
> From: Tommi Komulainen <tommi.komulainen <at> iki.fi>
> Date: Fri, 19 Jun 2015 18:53:52 +0200
> Subject: [PATCH] python.el: fix close paren indentation to match pep8
>
> When opening paren is followed by newline the closing paren should follow
> the current indentation. Otherwise the closing paren should be aligned
> with the opening paren. This fixes the latter case. #20742

I'm having trouble applying this.

    error: corrupt patch at line 11
    Applying: python.el: fix close paren indentation to match pep8
    Patch failed at 0001 python.el: fix close paren indentation to match pep8




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20742; Package emacs. (Sat, 20 Apr 2019 20:52:02 GMT) Full text and rfc822 format available.

Message #30 received at 20742 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: 20742 <at> debbugs.gnu.org
Cc: Tommi Komulainen <tommi.komulainen <at> iki.fi>
Subject: Re: bug#20742: 24.5;
 [PATCH] python.el: fix close paren indentation to match pep8
Date: Sat, 20 Apr 2019 16:51:23 -0400
[Message part 1 (text/plain, inline)]
tags 20742 + patch
quit

>> When opening paren is followed by newline the closing paren should follow
>> the current indentation. Otherwise the closing paren should be aligned
>> with the opening paren. This fixes the latter case. #20742
>
> I'm having trouble applying this.
>
>     error: corrupt patch at line 11
>     Applying: python.el: fix close paren indentation to match pep8
>     Patch failed at 0001 python.el: fix close paren indentation to match pep8

I managed to get this applied; I've replaced the python-test.el
modifications, partly because they're written as updates to the existing
tests which makes them a bit harder to follow, and partly to make more
clear that the patch is below the 15 line copyright limit.

I'll push to master in a week or so if there are no further comments.

[0001-python.el-Fix-close-paren-indentation-to-match-pep8-.patch (text/plain, attachment)]
[0002-Add-test-for-previous-change.patch (text/plain, attachment)]

Added tag(s) patch. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 20 Apr 2019 20:52:02 GMT) Full text and rfc822 format available.

Disconnected #20560 from all other report(s). Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 20 Apr 2019 20:59:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20742; Package emacs. (Sun, 28 Apr 2019 20:48:02 GMT) Full text and rfc822 format available.

Message #37 received at 20742 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: 20742 <at> debbugs.gnu.org
Cc: Tommi Komulainen <tommi.komulainen <at> iki.fi>
Subject: Re: bug#20742: 24.5;
 [PATCH] python.el: fix close paren indentation to match pep8
Date: Sun, 28 Apr 2019 16:47:15 -0400
tags 20742 fixed
close 20742 27.1
quit

> I'll push to master in a week or so if there are no further comments.

Done.

3fc1d77a43 2019-04-28T16:45:13-04:00 "python.el: Fix close paren indentation to match pep8 (Bug#20742)"
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=3fc1d77a43818666542740fc34167c1faee30d5f





Added tag(s) fixed. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 28 Apr 2019 20:48:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 27.1, send any further explanations to 20742 <at> debbugs.gnu.org and Tommi Komulainen <tommi.komulainen <at> iki.fi> Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 28 Apr 2019 20:48:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 27 May 2019 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 21 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.