autopep8: Problem with formatting f-strings on python3.12
Hey.
There is an issue with autopep8 and python3.12 that autopep8 tries to format the content inside the f-strings.
For instance
connector = f"socks5://{user}:{password}:{url}:{port}"
gets formatted to:
connector = f"socks5: //{user}: {password}: {url}: {port}"
The following is another sample:
About this issue
- Original URL
- State: closed
- Created 8 months ago
- Reactions: 12
- Comments: 18 (5 by maintainers)
Commits related to this issue
- yapf: use yapf instead of autopep8 autopep8 does not support Python 3.12, which is a requirement for moving to fedora:39. The following ticket has been open without comment from the development commu... — committed to bneradt/trafficserver by bneradt 7 months ago
- yapf: use yapf instead of autopep8 autopep8 does not support Python 3.12, which is a requirement for moving to fedora:39. The following ticket has been open without comment from the development commu... — committed to bneradt/trafficserver by bneradt 7 months ago
- yapf: use yapf instead of autopep8 autopep8 does not support Python 3.12, which is a requirement for moving to fedora:39. The following ticket has been open without comment from the development commu... — committed to bneradt/trafficserver by bneradt 7 months ago
- yapf: use yapf instead of autopep8 autopep8 does not support Python 3.12, which is a requirement for moving to fedora:39. The following ticket has been open without comment from the development commu... — committed to bneradt/trafficserver by bneradt 7 months ago
- yapf: use yapf instead of autopep8 autopep8 does not support Python 3.12, which is a requirement for moving to fedora:39. The following ticket has been open without comment from the development commu... — committed to bneradt/trafficserver by bneradt 7 months ago
- yapf: use yapf instead of autopep8 autopep8 does not support Python 3.12, which is a requirement for moving to fedora:39. The following ticket has been open without comment from the development commu... — committed to bneradt/trafficserver by bneradt 7 months ago
- yapf: use yapf instead of autopep8 autopep8 does not support Python 3.12, which is a requirement for moving to fedora:39. The following ticket has been open without comment from the development commu... — committed to bneradt/trafficserver by bneradt 7 months ago
- yapf: use yapf instead of autopep8 autopep8 does not support Python 3.12, which is a requirement for moving to fedora:39. The following ticket has been open without comment from the development commu... — committed to bneradt/trafficserver by bneradt 7 months ago
- yapf: use yapf instead of autopep8 autopep8 does not support Python 3.12, which is a requirement for moving to fedora:39. The following ticket has been open without comment from the development commu... — committed to bneradt/trafficserver by bneradt 7 months ago
- yapf: use yapf instead of autopep8 (#10860) autopep8 does not support Python 3.12, which is a requirement for moving to fedora:39. The following ticket has been open without comment from the develo... — committed to apache/trafficserver by bneradt 7 months ago
- yapf: use yapf instead of autopep8 autopep8 does not support Python 3.12, which is a requirement for moving to fedora:39. The following ticket has been open without comment from the development commu... — committed to bneradt/trafficserver by bneradt 7 months ago
- 9.2.x: yapf: use yapf instead of autopep8 (#10896) * yapf: use yapf instead of autopep8 autopep8 does not support Python 3.12, which is a requirement for moving to fedora:39. The following ticket... — committed to apache/trafficserver by bneradt 7 months ago
- work around formatter bug https://github.com/hhatto/autopep8/issues/712 — committed to s256/ios-backup by deleted user 5 months ago
- yapf: use yapf instead of autopep8 (#10860) autopep8 does not support Python 3.12, which is a requirement for moving to fedora:39. The following ticket has been open without comment from the develo... — committed to phongn/trafficserver by bneradt 7 months ago
- pyproject: support py3.12 via new version of pycodestyle autopep8 had some issues with python3.12. It seems just moving to the latest version of pycodestyle does fix the issue. Closes: https://githu... — committed to mvo5/autopep8 by mvo5 4 months ago
I see the same problem with the newline after
{in f strings but only with the pre-commit v2.0.4 hook. If run autopep8 v2.0.4 from the CLI everything seems to be okay. I have the following line in my code:With the autopep8 CLI (just the whitespaces will be fixed, e.g. what I would expect):
With autopep8 pre-commit (the linebreak after
{will be inserted):My pre-commit config is:
I don’t mean to come across as alarmist, but this is a serious bug. The https://github.com/apache/trafficserver project relies upon autopep8 to format its Python files, and this single issue keeping us from moving to
fedora:39because its system version of Python is 3.12. We use a pre-commit hook to block any commits that fail autopep8, so Apache Traffic Server devs currently cannot upgrade tofedora:39. Can the maintainer (@hhatto) please comment on the status of this issue and provide an ETA for the landing of its fix?Thank you for this tool. It has been helpful to the Apache Traffic Server project.
Kind regards, Brian
I have been hitting similar problem like @mvo5 . I have had identical version in use
autopep8 2.0.4 (pycodestyle: 2.10.0). For me solution was to upgrade pycodestyle to 2.11.1 which is bringing python3.12 support [1].[1] https://github.com/PyCQA/pycodestyle/blob/main/CHANGES.txt
@hhatto: Thanks for the reply.
Just in case it’s helpful, autopep8 on Python 3.12 greatly changes the white space within format strings, not only the addition of newlines. It adds or subtracts a variety of types of white space in various places. Here’s some samples of a run of it on the apache/trafficserver code base:
Removing white space
Adding spaces around colons:
Addition of newlines
You mentioned this above:
Here’s a particularly extreme example:
Removing newlines
In addition to additional newlines, it seems to also sometimes remove newlines:
Adding trailing white space
Note that the previous patch actually adds a trailing space at the end, which may not render in github.