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.58k stars 291 forks source link

Document `options` parameter in `fix_code()` #343

Open DamnedScholar opened 7 years ago

DamnedScholar commented 7 years ago

The documentation lists options for the CLI side of autopep8, but not for using it as a module. It's logical therefore to assume that all CLI options that make sense as module options would also be module options, but that does not seem to be the case.

My code:

data.write(autopep8.fix_code(output, options={'aggressive': 3, 'max-line-length': 70}))

The result:

Traceback (most recent call last):
  File "dbsync.py", line 172, in <module>
    main()
  File "dbsync.py", line 169, in main
    'max-line-length': 79}))
  File "D:\some\path\pyenv\lib\site-packages\autopep8.py", line 3015, in fix_code
    options = _get_options(options, apply_config)
  File "D:\some\path\pyenv\lib\site-packages\autopep8.py", line 3033, in _get_options
    raise ValueError("No such option '{}'".format(name))
ValueError: No such option 'max-line-length'

If the options for fix_code() are divergent from the CLI, that should be noted in the documentation.

myint commented 7 years ago

I think that should be max_line_length per argparse's normalization.

DamnedScholar commented 7 years ago

That ran successfully, thanks.

The other side of this issue is that the options for fix_code() should be listed in the README, so I'm leaving this open until they are. I had the thought to make the change myself, but they're not available from the source or docstring of fix_code(), either.