google / yapf

A formatter for Python files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The NO_SPACES_AROUND_SELECTED_BINARY_OPERATORS format option doesn't work correctly.

IWillChangeTheNameLater opened this issue · comments

commented

Using the NO_SPACES_AROUND_SELECTED_BINARY_OPERATORS = '&,|,^,/,*,@,**,%' formatting rule in a pyproject.toml file has two problems.
First, YAPF ignores the exponentiation operator because the operator consists of two characters.
Second, it raises the ValueError: invalid interpolation syntax in '%' at position 0 error because of "%" character in the string. The full error code:

Traceback (most recent call last):
  File "venv\Lib\site-packages\yapf\__init__.py", line 241, in _FormatFile
    reformatted_code, encoding, has_change = yapf_api.FormatFile(
                                             ^^^^^^^^^^^^^^^^^^^^
  File "venv\Lib\site-packages\yapf\yapflib\yapf_api.py", line 88, in FormatFile
    reformatted_source, changed = FormatCode(
                                  ^^^^^^^^^^^
  File "venv\Lib\site-packages\yapf\yapflib\yapf_api.py", line 203, in FormatCode
    reformatted_source = FormatTree(tree, style_config=style_config, lines=lines)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv\Lib\site-packages\yapf\yapflib\yapf_api.py", line 123, in FormatTree
    style.SetGlobalStyle(style.CreateStyleFromConfig(style_config))
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv\Lib\site-packages\yapf\yapflib\style.py", line 756, in CreateStyleFromConfig
    config = _CreateConfigParserFromConfigFile(style_config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv\Lib\site-packages\yapf\yapflib\style.py", line 809, in _CreateConfigParserFromConfigFile
    config.set('style', k, str(v))
  File "AppData\Local\Programs\Python\Python312\Lib\configparser.py", line 1182, in set
    super().set(section, option, value)
  File "AppData\Local\Programs\Python\Python312\Lib\configparser.py", line 872, in set
    value = self._interpolation.before_set(self, section, option,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "AppData\Local\Programs\Python\Python312\Lib\configparser.py", line 374, in before_set
    raise ValueError("invalid interpolation syntax in %r at "
ValueError: invalid interpolation syntax in '%' at position 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "venv\Scripts\yapf.exe\__main__.py", line 7, in <module>
  File "venv\Lib\site-packages\yapf\__init__.py", line 380, in run_main
    sys.exit(main(sys.argv))
             ^^^^^^^^^^^^^^
  File "venv\Lib\site-packages\yapf\__init__.py", line 139, in main
    changed = FormatFiles(
              ^^^^^^^^^^^^
  File "venv\Lib\site-packages\yapf\__init__.py", line 217, in FormatFiles
    changed |= _FormatFile(filename, lines, style_config, no_local_style,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv\Lib\site-packages\yapf\__init__.py", line 251, in _FormatFile
    raise errors.YapfError(errors.FormatErrorMsg(e))
                           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv\Lib\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)
                                 ~~~~~~^^^
IndexError: tuple index out of range