hhatto / autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide.
https://pypi.org/project/autopep8/
MIT License
4.56k stars 290 forks source link

Wrong function arguments indentation #344

Open vmstarchenko opened 7 years ago

vmstarchenko commented 7 years ago
# Before
func(asdfasdfa=(1, 1), basdfsadf=(1, 1), casdfasdf=(1, 1), kcasdfasdf=(1, 1), dcasdfasdf=(1, 1))

# After autopep8 file.py
# strange newline position: casdfasdf=(\n
func(asdfasdfa=(1, 1), basdfsadf=(1, 1), casdfasdf=(
    1, 1), kcasdfasdf=(1, 1), dcasdfasdf=(1, 1))

# After autopep8 -a -a file.py
# very strange newline position: argument=(\n multiple times
func(
    asdfasdfa=(
        1, 1), basdfsadf=(
            1, 1), casdfasdf=(
                1, 1), kcasdfasdf=(
                    1, 1), dcasdfasdf=(
                        1, 1))
# Before
if True:
    name0 = BarBarBarBarB(pool_size=(2, 2), strides=(2, 2), padding="food")(Food)

# After autopep8 -a -a file.py
if True:
    name0 = BarBarBarBarB(
        pool_size=(
            2, 2), strides=(
            2, 2), padding="food")(Food)
#          ^-- here must be 4 extra spaces

Position of newline symbols looks a bit strange. Furthermore in the second situation amount of spaces is not correct.

jamasi commented 6 years ago

I can confirm this with autopep8 0.9.1.

test = [xmod.yfunction(SomeModule.SomeClass, kwarg_1="cheese", kwarg_2=fish["sea.huge"], shop_closed = True),
        xmod.yfunction(SomeModule.AnotherClassWithSomeLongName,  kwarg_1="cheese", kwarg_2=fish["lake.too_small_to_keep_fishing"], shop_closed = True)]

$ autopep8 -a /tmp/test.py

test = [xmod.yfunction(
    SomeModule.SomeClass, kwarg_1="cheese", kwarg_2=fish["sea.huge"], shop_closed=True),
    xmod.yfunction(SomeModule.AnotherClassWithSomeLongName, kwarg_1="cheese", kwarg_2=fish["lake.too_small_to_keep_fishing"], shop_closed=True)]

I would expect code formatted like this:

test = [
    xmod.yfunction(SomeModule.SomeClass,
        kwarg_1="cheese",
        kwarg_2=fish["sea.huge"],
        shop_closed=True),
    xmod.yfunction(SomeModule.AnotherClassWithSomeLongName,
        kwarg_1="cheese",
        kwarg_2=fish["lake.too_small_to_keep_fishing"],
        shop_closed=True)
    ]

or even nicer:

test = [
    xmod.yfunction(
        SomeModule.SomeClass,
        kwarg_1="cheese",
        kwarg_2=fish["sea.huge"],
        shop_closed=True),
    xmod.yfunction(
        SomeModule.AnotherClassWithSomeLongName,
        kwarg_1="cheese",
        kwarg_2=fish["lake.too_small_to_keep_fishing"],
        shop_closed=True)
    ]