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

--experimental --max-line-length does not work on Python 3.12 with f-strings inside of a dict #745

Closed
daniel-afana opened this issue May 16, 2024 · 1 comment · Fixed by #747
Labels

Comments

@daniel-afana
Copy link

daniel-afana commented May 16, 2024

The error occurs when the max line length is exceeded, and there is a dict with an f-string inside

Python Code

s = "Some string"
fstring = {"some_key": f"There is a string value inside of an f string, which itself is a dictionary value {s})"}

Command Line

$ autopep8 --experimental --diff --max-line-length=79 my_file.py

Your Environment

  • Python version: 3.12
  • autopep8 version: 2.1.0
  • Platform: linux (Ubuntu 20.04), macOS Sonoma 14.4.1

The Error

Traceback (most recent call last):
  File ".../virtualenvs/autopep-test/bin/autopep8", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 4499, in main
    results = fix_multiple_files(args.files, args, sys.stdout)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 4394, in fix_multiple_files
    ret = _fix_file((name, options, output))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 4364, in _fix_file
    return fix_file(*parameters)
           ^^^^^^^^^^^^^^^^^^^^^
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 3570, in fix_file
    fixed_source = fix_lines(fixed_source, options, filename=filename)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 3550, in fix_lines
    fixed_source = fix.fix()
                   ^^^^^^^^^
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 617, in fix
    self._fix_source(filter_results(source=''.join(self.source),
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 559, in _fix_source
    modified_lines = fix(result, logical)
                     ^^^^^^^^^^^^^^^^^^^^
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 987, in fix_long_line_logically
    return self.fix_long_line_physically(result)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 1024, in fix_long_line_physically
    fixed = self.fix_long_line(
            ^^^^^^^^^^^^^^^^^^^
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 1053, in fix_long_line
    fixed = get_fixed_long_line(
            ^^^^^^^^^^^^^^^^^^^^
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 1622, in get_fixed_long_line
    sorted(set(candidates).union([target, original])),
           ^^^^^^^^^^^^^^^
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 1902, in shorten_line
    for shortened in _shorten_line_at_tokens_new(
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 2783, in _shorten_line_at_tokens_new
    fixed = _reflow_lines(parsed_tokens, indentation, max_line_length,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 2760, in _reflow_lines
    item.reflow(lines, continued_indent, break_after_open_bracket)
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 2385, in reflow
    reflowed_lines.add(self, len(continued_indent),
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 2053, in add
    self._add_item(obj, indent_amt)
  File ".../virtualenvs/autopep-test/lib/python3.12/site-packages/autopep8.py", line 2202, in _add_item
    assert self._bracket_depth >= 0
           ^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
@hhatto
Copy link
Owner

hhatto commented May 28, 2024

fix in v2.1.2
https://pypi.org/project/autopep8/2.1.2/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants