bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#34268: 27.0.50; wrong indentation in python mode


From: Augusto Stoffel
Subject: bug#34268: 27.0.50; wrong indentation in python mode
Date: Thu, 23 Sep 2021 23:08:19 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

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.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]