all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Augusto Stoffel <arstoffel@gmail.com>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: Valentin Ignatev <valentignatev@gmail.com>,
	sds@gnu.org, 34268@debbugs.gnu.org
Subject: bug#34268: 27.0.50; wrong indentation in python mode
Date: Thu, 23 Sep 2021 23:08:19 +0200	[thread overview]
Message-ID: <8735pvhuf0.fsf@gmail.com> (raw)
In-Reply-To: <877df8qnmn.fsf_-_@gnus.org> (Lars Ingebrigtsen's message of "Wed, 22 Sep 2021 23:57:52 +0200")

On Wed, 22 Sep 2021 at 23:57, Lars Ingebrigtsen <larsi@gnus.org> wrote:

> Valentin Ignatev <valentignatev@gmail.com> writes:
>
>> Hey Sam, I've looked in the python.el code and it seems that it reuses
>> python-indent-def-block-scale for calculating an indentation.
>>
>> The default value is 2 which is why inside-parens indent doubles. Setting its
>> value to 1 fixes the issue.
>>
>> I also wonder why authors choose double indent for aligning function
>> arguments. Is this some kind of an oldschool code style? :) 
>
> (I'm going through old bug reports that unfortunately weren't resolved
> at the time.)
>
> If I understand correctly (and I may well not -- I don't write much
> python), this is just a preference issue, and setting
> `python-indent-def-block-scale' to 1 fixes the issue?
>
> If that's what's recommended by the standards, should we flip the
> default to 1?
>
> I've added Augusto to the CCs; perhaps he has an opinion here.

I have no idea about what strong opinions other people may have here,
but after looking a bit into this I think 1 is probably a better default
for `python-indent-def-block-scale'. Here's what I found out:

The current default of 2 for `python-indent-def-block-scale' is meant to
produce this indentation style

```
def long_function_name(
        var_one, var_two, var_three,
        var_four):
    print(var_one)
```

which is exactly as one can find in PEP-8.  Setting it to 1 produces

```
def long_function_name(
    var_one, var_two, var_three,
    var_four):
    print(var_one)
```

which is deemed wrong in that document.

However, the above formatting looks quite unfamiliar to me anyway.  I
usually see one of the following styles:

```
# By far the most common style in the Python source, and, I, think, the
# default style of YAPF
def long_function_name(var_one, var_two, var_three,
                       var_four):
    print(var_one)
```

which is insensitive to `python-indent-def-block-scale', or else

```
# Black does that, like it or not
def long_function_name(
    var_one, var_two, var_three,
    var_four
):
    print(var_one)
```

in which case a value of 1 for `python-indent-def-block-scale' is the
right thing.

Finally, the situation mentioned originally in this bug report seems to
be a glitch: an indentation rule that makes sense in a "for" statement
is being applied where a "for" appears in a list comprehension.  It's a
rather minor detail, I'd say.





  parent reply	other threads:[~2021-09-23 21:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-31 21:04 bug#34268: 27.0.50; wrong indentation in python mode Sam Steingold
2019-02-19 13:13 ` Bhavin Gandhi
2019-02-19 13:53   ` Sam Steingold
2019-06-09 21:24 ` bug#34268: Configuration option to fix the issue Valentin Ignatev
2021-09-22 21:57   ` bug#34268: 27.0.50; wrong indentation in python mode Lars Ingebrigtsen
2021-09-23 12:37     ` Andreas Röhler
2021-09-23 21:08     ` Augusto Stoffel [this message]
2021-09-23 22:01       ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8735pvhuf0.fsf@gmail.com \
    --to=arstoffel@gmail.com \
    --cc=34268@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=sds@gnu.org \
    --cc=valentignatev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.