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

autopep8 refuses to break long line #380

Open philsc opened 6 years ago

philsc commented 6 years ago

I found a line of code at work that autopep8 won't format.

Here's a minimal example of this:

#!/usr/bin/env python3

class Foo(object):
    def a(self):
        (return_value1, return_value2) = self.b_with_somewhat_long_name('past_80_chars')

    def b_with_somewhat_long_name(self, bar):
        return (1, 1)

This is what I run:

$ autopep8 --max-line-length=80 -i -aaaaaaaaa --experimental -v -v -v -v foo.py
[file:foo.py]
--->  Applying global fix for E265
--->  Applying global fix for W602
--->  1 issue(s) to fix {'E501': set([6])}
-------------------------------------------------------------------------------
        (return_value1, return_value2) = self.b_with_somewhat_long_name('past_80_chars')
-------------------------------------------------------------------------------
        (return_value1, return_value2) = self.b_with_somewhat_long_name(
            'past_80_chars')
-------------------------------------------------------------------------------
        (return_value1,
     return_value2) = self.b_with_somewhat_long_name('past_80_chars')
-------------------------------------------------------------------------------
        (return_value1,
         return_value2) = self.b_with_somewhat_long_name('past_80_chars')
-------------------------------------------------------------------------------
        (
            return_value1, return_value2) = self.b_with_somewhat_long_name(
            'past_80_chars')
-------------------------------------------------------------------------------
        (
    return_value1,
     return_value2) = self.b_with_somewhat_long_name('past_80_chars')
-------------------------------------------------------------------------------
        (
    return_value1, return_value2) = self.b_with_somewhat_long_name('past_80_chars')
-------------------------------------------------------------------------------
        (
            return_value1, return_value2) = self.b_with_somewhat_long_name('past_80_chars')
-------------------------------------------------------------------------------

--->  Not fixing E501 on line 6

Is autopep8 confused here because it has too many options to choose from? I would have expected it to pick the first option there. I.e. not the original line, but the one after it:

        (return_value1, return_value2) = self.b_with_somewhat_long_name(
            'past_80_chars')

More details:

$ autopep8 --version
autopep8 1.3.2 (pycodestyle: 2.3.1)
$ python3 --version
Python 3.4.2
$ python --version
Python 2.7.9
$ uname -a
Linux dev-builder 4.9.53 #2 SMP PREEMPT Thu Dec 7 15:05:31 PST 2017 x86_64 GNU/Linux

I don't have enough control over this box to install the latest version (or pip for that matter). I can give it a try later this weekend on a different machine.

psavery commented 6 years ago

I was having a little bit of trouble with this as well...

bkietz commented 3 years ago

I believe the following is related, but I'm not sure what the correct output from autopep8 would be

def make_dict(super_long_name_which_overflows):
    return dict(super_long_name_which_overflows=
            super_long_name_which_overflows)

$ autopep8 -aaaaaa -v -v -v -v --experimental make_dict.py

[file:repro.py]
--->  Applying global fix for E265
--->  Applying global fix for E231
--->  Applying global fix for E721
--->  Applying global fix for W601
--->  Applying global fix for W603
--->  Applying global fix for W604
--->  Applying global fix for W690
--->  2 issue(s) to fix {'E128': {3}, 'E251': {2}}
--->  3 issue(s) to fix {'E501': {2}, 'E251': {2}, 'E222': {2}}
--->  1 issue(s) to fix {'E501': {2}}
-------------------------------------------------------------------------------
    return dict(super_long_name_which_overflows=super_long_name_which_overflows)
-------------------------------------------------------------------------------
    return dict(
    super_long_name_which_overflows=super_long_name_which_overflows)
-------------------------------------------------------------------------------
    return dict(
        super_long_name_which_overflows=super_long_name_which_overflows)
-------------------------------------------------------------------------------
    return dict(
                super_long_name_which_overflows=super_long_name_which_overflows)
-------------------------------------------------------------------------------

--->  Not fixing E501 on line 2
def make_dict(super_long_name_which_overflows):
    return dict(super_long_name_which_overflows=super_long_name_which_overflows)