4

With the following autopep8 command:

autopep8 --pep8-passes 2000 --verbose --aggressive --aggressive --ignore=E501,E722

and python code fragment:

parser.add_argument('-a', '--auto', help='Activate automatic semi-intelligent inference for --some-long-flags and --other-long-flags.  '
    '--some-long-flags will be activated when the primary manifold script is presented with a single-node cluster.  '
    '--other-long-flags will be enabled when no resources are specified in the helm overrides file.', action='store_true')

the final result is:

parser.add_argument('-a', '--auto', help='Activate automatic semi-intelligent inference for --some-long-flags and --other-long-flags.  '
                    '--some-long-flags will be activated when the primary manifold script is presented with a single-node cluster.  '
                    '--other-long-flags will be enabled when no resources are specified in the helm overrides file.', action='store_true')

Notice how the multi-line indentation of the --auto flag is now aligned to the end of the parser.add_argument( block, rather than indenting 1 level deeper than the parent.

I understand that it is what pep8 advises as the recommended way. At the same time, personally, I despise this formatting style, and find it:

  • Inconsistent and arbitrary based on the length of function string names.

  • Very annoying to type manually when not using an IDE or editor with awareness for this style.

I'm not sure what the proper name for this style of code formatting, IntelliJ seems to refer to it as a "Continuation indent". Is there a way to gently steer autopep8 away from forcing this style?


Also see the full runnable example code inputs and outputs with a pretty diff view of edits autopep8 wants to apply.

Jay Taylor
  • 13,185
  • 11
  • 60
  • 85
  • PEP-8 would seem to suggest moving `-a` et al. down to the second line. – chepner Apr 06 '18 at 19:18
  • Yes, this workaround avoids the ugly continuation indent! I'd still also really love to find out how to disable the behavior altogether, if possible. – Jay Taylor Apr 06 '18 at 19:26

0 Answers0