Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Python 3.12 feature: PEP 613 Explicit Type Alias #1266

Open
Garrett-R opened this issue Feb 9, 2025 · 0 comments
Open

Support Python 3.12 feature: PEP 613 Explicit Type Alias #1266

Garrett-R opened this issue Feb 9, 2025 · 0 comments

Comments

@Garrett-R
Copy link
Contributor

In PEP 613, this is valid Python:

type NumDingleberries = int

but running the latest YAPF (0.43.0) gives an error:

Traceback (most recent call last):
  File "/home/garrett/.virtualenvs/tester/lib/python3.12/site-packages/yapf/yapflib/yapf_api.py", line 198, in FormatCode
    tree = pytree_utils.ParseCodeToTree(unformatted_source)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/garrett/.virtualenvs/tester/lib/python3.12/site-packages/yapf/pytree/pytree_utils.py", line 113, in ParseCodeToTree
    tree = parser_driver.parse_string(code, debug=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/garrett/.virtualenvs/tester/lib/python3.12/site-packages/yapf_third_party/_ylib2to3/pgen2/driver.py", line 187, in parse_string
    return self.parse_tokens(tokens, debug)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/garrett/.virtualenvs/tester/lib/python3.12/site-packages/yapf_third_party/_ylib2to3/pgen2/driver.py", line 156, in parse_tokens
    if p.addtoken(type, value, (prefix, start)):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/garrett/.virtualenvs/tester/lib/python3.12/site-packages/yapf_third_party/_ylib2to3/pgen2/parse.py", line 230, in addtoken
    return self._addtoken(ilabel, type, value, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/garrett/.virtualenvs/tester/lib/python3.12/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='NumDingleberries', context=(' ', (1, 5))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/garrett/.virtualenvs/tester/lib/python3.12/site-packages/yapf/__init__.py", line 238, in _FormatFile
    reformatted_code, encoding, has_change = yapf_api.FormatFile(
                                             ^^^^^^^^^^^^^^^^^^^^
  File "/home/garrett/.virtualenvs/tester/lib/python3.12/site-packages/yapf/yapflib/yapf_api.py", line 88, in FormatFile
    reformatted_source, changed = FormatCode(
                                  ^^^^^^^^^^^
  File "/home/garrett/.virtualenvs/tester/lib/python3.12/site-packages/yapf/yapflib/yapf_api.py", line 201, in FormatCode
    raise errors.YapfError(errors.FormatErrorMsg(e))
                           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/garrett/.virtualenvs/tester/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)
                                 ~~~~~~^^^
IndexError: tuple index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/garrett/.virtualenvs/tester/bin/yapf", line 8, in <module>
    sys.exit(run_main())
             ^^^^^^^^^^
  File "/home/garrett/.virtualenvs/tester/lib/python3.12/site-packages/yapf/__init__.py", line 377, in run_main
    sys.exit(main(sys.argv))
             ^^^^^^^^^^^^^^
  File "/home/garrett/.virtualenvs/tester/lib/python3.12/site-packages/yapf/__init__.py", line 136, in main
    changed = FormatFiles(
              ^^^^^^^^^^^^
  File "/home/garrett/.virtualenvs/tester/lib/python3.12/site-packages/yapf/__init__.py", line 214, in FormatFiles
    changed |= _FormatFile(filename, lines, style_config, no_local_style,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/garrett/.virtualenvs/tester/lib/python3.12/site-packages/yapf/__init__.py", line 248, in _FormatFile
    raise errors.YapfError(errors.FormatErrorMsg(e))
                           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/garrett/.virtualenvs/tester/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)
                                 ~~~~~~^^^
IndexError: tuple index out of range

Note: similar to #1170 which also adds support for a Python 3.12 feature

polarG added a commit to microsoft/superbenchmark that referenced this issue Feb 25, 2025
Added support for Python 3.11, 3.12 and 3.13.

yapf is not compatiable with python3.12+, so we disable yapf in py3.12
for now.
google/yapf#1258
google/yapf#1266

---------

Co-authored-by: hongtaozhang <hongtaozhang@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant