Search code examples
pythonpython-3.xlinterautopep8

ValueError when running autopep8


I'm trying to run autopep8 recursively in a directory named "tests" with following command:

autopep8 --in-place --recursive tests

But I'm facing an odd error when running the command:

.pyenv/versions/3.11.4/lib/python3.11/configparser.py", line 819, in _get
    return conv(self.get(section, option, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'True'

I already tried other valid commands to try and run autopep8 but none worked. How can I fix this issue?

[EDIT] Whole stack:

autopep8 tests --in-place --recursive --verbose
read config path: /home/acabista/Documents/automations/rainmaker/api-automation/tox.ini
Traceback (most recent call last):
  File "/home/acabista/.pyenv/versions/rainmaker-api/bin/autopep8", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/acabista/.pyenv/versions/rainmaker-api/lib/python3.11/site-packages/autopep8.py", line 4499, in main
    args = parse_args(argv[1:], apply_config=apply_config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/acabista/.pyenv/versions/rainmaker-api/lib/python3.11/site-packages/autopep8.py", line 3835, in parse_args
    parser = read_config(args, parser)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/acabista/.pyenv/versions/rainmaker-api/lib/python3.11/site-packages/autopep8.py", line 4013, in read_config
    for norm_opt, k, value in _get_normalize_options(
  File "/home/acabista/.pyenv/versions/rainmaker-api/lib/python3.11/site-packages/autopep8.py", line 3970, in _get_normalize_options
    value = config.getint(section, k)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/acabista/.pyenv/versions/3.11.4/lib/python3.11/configparser.py", line 834, in getint
    return self._get_conv(section, option, int, raw=raw, vars=vars,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/acabista/.pyenv/versions/3.11.4/lib/python3.11/configparser.py", line 824, in _get_conv
    return self._get(section, conv, option, raw=raw, vars=vars,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/acabista/.pyenv/versions/3.11.4/lib/python3.11/configparser.py", line 819, in _get
    return conv(self.get(section, option, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'True'

Solution

  • autopep8 uses configparser to read .ini files. It expected to read an integer option but got the string "True" instead. Unfortunately, neither autopep8 or configparser are very good at telling you which option was bad. Potentially one could put a breakpoint in configparser to catch the error - you'll find that the erring line is in a try/except block and you can breakpoint the exception - but otherwise, manual inspection of the config file is due.