Skip to content

omitting [style] breaks yapf #1286

@dgutson

Description

@dgutson

this config

allow_multiline_dictionary_keys = False

(without the [style] header) causes yapf without catching the exception:

Traceback (most recent call last):
  File "/home/daniel/.local/share/pipx/venvs/yapf/lib/python3.12/site-packages/yapf/__init__.py", line 238, in _FormatFile
    reformatted_code, encoding, has_change = yapf_api.FormatFile(
                                             ^^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/.local/share/pipx/venvs/yapf/lib/python3.12/site-packages/yapf/yapflib/yapf_api.py", line 88, in FormatFile
    reformatted_source, changed = FormatCode(
                                  ^^^^^^^^^^^
  File "/home/daniel/.local/share/pipx/venvs/yapf/lib/python3.12/site-packages/yapf/yapflib/yapf_api.py", line 203, in FormatCode
    reformatted_source = FormatTree(tree, style_config=style_config, lines=lines)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/.local/share/pipx/venvs/yapf/lib/python3.12/site-packages/yapf/yapflib/yapf_api.py", line 123, in FormatTree
    style.SetGlobalStyle(style.CreateStyleFromConfig(style_config))
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/.local/share/pipx/venvs/yapf/lib/python3.12/site-packages/yapf/yapflib/style.py", line 774, in CreateStyleFromConfig
    config = _CreateConfigParserFromConfigFile(style_config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/.local/share/pipx/venvs/yapf/lib/python3.12/site-packages/yapf/yapflib/style.py", line 824, in _CreateConfigParserFromConfigFile
    config.read_file(style_file)
  File "/usr/lib/python3.12/configparser.py", line 705, in read_file
    self._read(f, source)
  File "/usr/lib/python3.12/configparser.py", line 1064, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
configparser.MissingSectionHeaderError: File contains no section headers.
file: '/home/daniel/src/.style.yapf', line: 1
'allow_multiline_dictionary_keys = False\n'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/daniel/.local/bin/yapf", line 7, in <module>
    sys.exit(run_main())
             ^^^^^^^^^^
  File "/home/daniel/.local/share/pipx/venvs/yapf/lib/python3.12/site-packages/yapf/__init__.py", line 377, in run_main
    sys.exit(main(sys.argv))
             ^^^^^^^^^^^^^^
  File "/home/daniel/.local/share/pipx/venvs/yapf/lib/python3.12/site-packages/yapf/__init__.py", line 136, in main
    changed = FormatFiles(
              ^^^^^^^^^^^^
  File "/home/daniel/.local/share/pipx/venvs/yapf/lib/python3.12/site-packages/yapf/__init__.py", line 214, in FormatFiles
    changed |= _FormatFile(filename, lines, style_config, no_local_style,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/.local/share/pipx/venvs/yapf/lib/python3.12/site-packages/yapf/__init__.py", line 248, in _FormatFile
    raise errors.YapfError(errors.FormatErrorMsg(e))
                           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/.local/share/pipx/venvs/yapf/lib/python3.12/site-packages/yapf/yapflib/errors.py", line 37, in FormatErrorMsg
    return '{}:{}:{}: {}'.format(e.args[1][0], e.args[1][1], e.args[1][2], e.msg)
                                 ~~~~~~~~~^^^
TypeError: 'int' object is not subscriptable

I installed yapf through pipx install yapf.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions