Subject: bug#33979: 26.1; python.el is not fully PEP 8 compliant for closing parens

From: Barry Warsaw <[email-masked]>
Date: Fri, 4 Jan 2019 15:48:00 -0500

I am spending some time playing with the default python.el to see where
it differs from the externally maintained python-mode.el.  AFAICT,
python.el does not fully support PEP 8 (the document, not the tool) for
the indentation of closing parentheses.

Given this code, typed contemporaneously:

NUMBERS = [
    (1, 2),
    (3, 4),
    (5, 6),
           ^----point

Now I hit RET and ]

NUMBERS = [
    (1, 2),
    (3, 4),
    (5, 6),
    ]
     ^----point

However, if I hit TAB at point, the closing bracket gets moved to column
0:

NUMBERS = [
    (1, 2),
    (3, 4),
    (5, 6),
]

While this style is PEP 8 compliant, so is this:

NUMBERS = [
    (1, 2),
    (3, 4),
    (5, 6),
    ]

i.e. with the closing brace lined up under the beginning of the last
line.  Quoting PEP 8:

> The closing brace/bracket/parenthesis on multiline constructs may
> either line up under the first non-whitespace character of the last
> line of list, as in: [EXAMPLES THAT LOOK LIKE WHAT I WANT]
> ...
> or it may be lined up under the first character of the line that
> starts the multiline construct, as in: [EXAMPLES THAT LOOK LIKE
> PYTHON.EL]

I've looked at python-indent--calculate-indentation in python.el and
AFAICT, there's no way to customize this behavior.  Thus, python.el
violates PEP 8.

In GNU Emacs 26.1 (build 1, x86_64-apple-darwin17.5.0, NS appkit-1561.40 Version 10.13.4 (Build 17E202))
of 2018-05-30 built on resist.local
Windowing system distributor 'Apple', version 10.3.1671
Recent messages:
Checking 24 files in /usr/local/Cellar/emacs/26.1_1/share/emacs/26.1/lisp/cedet...
Checking 57 files in /usr/local/Cellar/emacs/26.1_1/share/emacs/26.1/lisp/calendar...
Checking 87 files in /usr/local/Cellar/emacs/26.1_1/share/emacs/26.1/lisp/calc...
Checking 105 files in /usr/local/Cellar/emacs/26.1_1/share/emacs/26.1/lisp/obsolete...
Checking for load-path shadows...done
You can run the command ‘report-emacs-bug’ with M-x r-em RET
Checking for load-path shadows...done
previous-line: Beginning of buffer [8 times]
Quit [6 times]
report-emacs-bug-insert-to-mailer: Subject, To or body not found
Quit [2 times]
Configured using:
'configure --disable-dependency-tracking --disable-silent-rules
--enable-locallisppath=/usr/local/share/emacs/site-lisp
--infodir=/usr/local/Cellar/emacs/26.1_1/share/info/emacs
--prefix=/usr/local/Cellar/emacs/26.1_1 --with-gnutls --without-x
--with-xml2 --without-dbus --without-imagemagick --with-ns
--disable-ns-self-contained'

Configured features:
JPEG NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS THREADS

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Py