This bug is reproducible with the following basic code and the most recent version of yapf 0.43.0:
from logging import getLogger
LOG = getLogger(__name__)
roi_dict = {"ROI": "roi_1"}
LOG.info(f"ROI loaded: name={roi_dict["ROI"]}")
Traceback (most recent call last):
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\Lib\site-packages\yapf\yapflib\yapf_api.py", line 198, in FormatCode
tree = pytree_utils.ParseCodeToTree(unformatted_source)
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\Lib\site-packages\yapf\pytree\pytree_utils.py", line 113, in ParseCodeToTree
tree = parser_driver.parse_string(code, debug=False)
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\Lib\site-packages\yapf_third_party\_ylib2to3\pgen2\driver.py", line 187, in parse_string
return self.parse_tokens(tokens, debug)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\Lib\site-packages\yapf_third_party\_ylib2to3\pgen2\driver.py", line 156, in parse_tokens
if p.addtoken(type, value, (prefix, start)):
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\Lib\site-packages\yapf_third_party\_ylib2to3\pgen2\parse.py", line 230, in addtoken
return self._addtoken(ilabel, type, value, context)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\Lib\site-packages\yapf_third_party\_ylib2to3\pgen2\parse.py", line 313, in _addtoken
raise ParseError('bad input', type, value, context)
yapf_third_party._ylib2to3.pgen2.parse.ParseError: bad input: type=1, value='ROI', context=('', (9, 39))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\Lib\site-packages\yapf\__init__.py", line 238, in _FormatFile
reformatted_code, encoding, has_change = yapf_api.FormatFile(
~~~~~~~~~~~~~~~~~~~^
filename,
^^^^^^^^^
...<3 lines>...
print_diff=print_diff,
^^^^^^^^^^^^^^^^^^^^^^
logger=logging.warning)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\Lib\site-packages\yapf\yapflib\yapf_api.py", line 88, in FormatFile
reformatted_source, changed = FormatCode(
~~~~~~~~~~^
original_source,
^^^^^^^^^^^^^^^^
...<2 lines>...
lines=lines,
^^^^^^^^^^^^
print_diff=print_diff)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\Lib\site-packages\yapf\yapflib\yapf_api.py", line 201, in FormatCode
raise errors.YapfError(errors.FormatErrorMsg(e))
~~~~~~~~~~~~~~~~~~~~~^^^
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\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
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\Scripts\yapf-script.py", line 9, in <module>
sys.exit(run_main())
~~~~~~~~^^
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\Lib\site-packages\yapf\__init__.py", line 377, in run_main
sys.exit(main(sys.argv))
~~~~^^^^^^^^^^
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\Lib\site-packages\yapf\__init__.py", line 136, in main
changed = FormatFiles(
files,
...<7 lines>...
verbose=args.verbose,
print_modified=args.print_modified)
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\Lib\site-packages\yapf\__init__.py", line 214, in FormatFiles
changed |= _FormatFile(filename, lines, style_config, no_local_style,
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
in_place, print_diff, quiet, verbose,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
print_modified)
^^^^^^^^^^^^^^^
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\Lib\site-packages\yapf\__init__.py", line 248, in _FormatFile
raise errors.YapfError(errors.FormatErrorMsg(e))
~~~~~~~~~~~~~~~~~~~~~^^^
File "C:\Users\ddb29996\AppData\Local\miniforge3\envs\yapf-testing\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
Note that there is a workaround for this error if you assign the accessed dict to a variable:
from logging import getLogger
LOG = getLogger(__name__)
roi_dict = {"ROI": "roi_1"}
roi_name = roi_dict["ROI"]
LOG.info(f"ROI loaded: name={roi_name}")
When using a dict directly inside
logging.getLogger.info(), it leads to ayapf_third_party._ylib2to3.pgen2.parse.ParseErrorThis bug is reproducible with the following basic code and the most recent version of
yapf 0.43.0:Leading to the following error:
Note that there is a workaround for this error if you assign the accessed dict to a variable: