hhatto / autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide.
https://pypi.org/project/autopep8/
MIT License
4.54k stars 291 forks source link

Test failures with Python 3.12 #706

Closed mgorny closed 4 months ago

mgorny commented 11 months ago

When running the test suite under Python 3.12.0rc1, I'm getting the following test failures:

$ tox -e py312
py312: install_deps> python -I -m pip install 'pycodestyle>=2.9.1' 'pydiff>=0.1.2'
.pkg: _optional_hooks> python /usr/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: get_requires_for_build_sdist> python /usr/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: build_sdist> python /usr/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta
py312: install_package_deps> python -I -m pip install 'pycodestyle>=2.10.0' 'tomli; python_version < "3.11"'
py312: install_package> python -I -m pip install --force-reinstall --no-deps /tmp/autopep8/.tox/.tmp/package/2/autopep8-2.0.4.tar.gz
py312: commands[0]> python test/test_autopep8.py
........../tmp/autopep8/autopep8.py:182: DeprecationWarning: lib2to3 package is deprecated and may not be able to parse Python 3.10+
  from lib2to3.pgen2 import tokenize as lib2to3_tokenize
..........--indent-size must be greater than 0...................F....[file:/tmp/autopep8test3o49frzk/foo.py]
--->  0 issue(s) to fix {}
.[file:/tmp/autopep8testsr4990b5/foo.py]
--->  1 issue(s) to fix {'E222': {1}}
--->  0 issue(s) to fix {}
.[file:/tmp/autopep8testhei0ocax/foo.py]
--->  1 issue(s) to fix {'E222': {1}}
--->  0 issue(s) to fix {}
read config path: /dev/null
read config path: /tmp/autopep8/test/fake_configuration/.pep8
enable config: section=pep8, key=indent-size, value=2
...............s...........................F..........s..........................................................................................................................................................................................................................................................F...........................................................F................................................................................................................................................
======================================================================
FAIL: test_verbose (__main__.CommandLineTests.test_verbose)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/autopep8/test/test_autopep8.py", line 5474, in test_verbose
    self.assertIn("'fix_e901' is not defined", verbose_error)
AssertionError: "'fix_e901' is not defined" not found in "[file:/tmp/fh_r8mwb]\n--->  2 issue(s) to fix {'W292': {1}}\n--->  0 issue(s) to fix {}\n"

======================================================================
FAIL: test_e501_experimental_parsing_dict_with_comments (__main__.ExperimentalSystemTests.test_e501_experimental_parsing_dict_with_comments)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/autopep8/autopep8.py", line 995, in fix_long_line_logically
    fixed = self.fix_long_line(
            ^^^^^^^^^^^^^^^^^^^
  File "/tmp/autopep8/autopep8.py", line 1049, in fix_long_line
    fixed = get_fixed_long_line(
            ^^^^^^^^^^^^^^^^^^^^
  File "/tmp/autopep8/autopep8.py", line 1554, in get_fixed_long_line
    tokens = list(generate_tokens(source))
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/autopep8/autopep8.py", line 4566, in generate_tokens
    self.last_tokens = list(
                       ^^^^^
  File "/usr/lib/python3.12/tokenize.py", line 543, in _generate_tokens_from_c_tokenizer
    raise TokenError(msg, (e.lineno, e.offset)) from None
tokenize.TokenError: ('unexpected EOF in multi-line statement', (1, 0))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/autopep8/test/test_autopep8.py", line 7228, in test_e501_experimental_parsing_dict_with_comments
    with autopep8_context(line, options=['--experimental']) as result:
  File "/usr/lib/python3.12/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/tmp/autopep8/test/test_autopep8.py", line 7321, in autopep8_context
    yield autopep8.fix_file(filename=filename, options=options)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/autopep8/autopep8.py", line 3595, in fix_file
    fixed_source = fix_lines(fixed_source, options, filename=filename)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/autopep8/autopep8.py", line 3575, in fix_lines
    fixed_source = fix.fix()
                   ^^^^^^^^^
  File "/tmp/autopep8/autopep8.py", line 613, in fix
    self._fix_source(filter_results(source=''.join(self.source),
  File "/tmp/autopep8/autopep8.py", line 555, in _fix_source
    modified_lines = fix(result, logical)
                     ^^^^^^^^^^^^^^^^^^^^
  File "/tmp/autopep8/autopep8.py", line 1001, in fix_long_line_logically
    return self.fix_long_line_physically(result)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/autopep8/autopep8.py", line 1020, in fix_long_line_physically
    fixed = self.fix_long_line(
            ^^^^^^^^^^^^^^^^^^^
  File "/tmp/autopep8/autopep8.py", line 1049, in fix_long_line
    fixed = get_fixed_long_line(
            ^^^^^^^^^^^^^^^^^^^^
  File "/tmp/autopep8/autopep8.py", line 1566, in get_fixed_long_line
    sorted(set(candidates).union([target, original])),
           ^^^^^^^^^^^^^^^
  File "/tmp/autopep8/autopep8.py", line 1909, in shorten_line
    for shortened in _shorten_line_at_tokens_new(
  File "/tmp/autopep8/autopep8.py", line 2790, in _shorten_line_at_tokens_new
    fixed = _reflow_lines(parsed_tokens, indentation, max_line_length,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/autopep8/autopep8.py", line 2767, in _reflow_lines
    item.reflow(lines, continued_indent, break_after_open_bracket)
  File "/tmp/autopep8/autopep8.py", line 2392, in reflow
    reflowed_lines.add(self, len(continued_indent),
  File "/tmp/autopep8/autopep8.py", line 2060, in add
    self._add_item(obj, indent_amt)
  File "/tmp/autopep8/autopep8.py", line 2209, in _add_item
    assert self._bracket_depth >= 0
AssertionError

======================================================================
FAIL: test_e701_with_escaped_newline_and_spaces (__main__.SystemTests.test_e701_with_escaped_newline_and_spaces)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/autopep8/test/test_autopep8.py", line 3945, in test_e701_with_escaped_newline_and_spaces
    self.assertEqual(fixed, result)
AssertionError: 'if True:\n    print True\n' != 'if True:    \\   \nprint True\n'
- if True:
+ if True:    \   
-     print True
? ----
+ print True

======================================================================
FAIL: test_e901_should_cause_indentation_screw_up (__main__.SystemTests.test_e901_should_cause_indentation_screw_up)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/autopep8/test/test_autopep8.py", line 4431, in test_e901_should_cause_indentation_screw_up
    self.assertEqual(line, result)
AssertionError: 'def tmp(g):\n    g(4)))\n\n    if not True:\n        pass\n        pass\n' != 'def tmp(g):\n    g(4)))\n\n        if not True:\n        pass\n        pass\n'
  def tmp(g):
      g(4)))

-     if not True:
+         if not True:
? ++++
          pass
          pass

----------------------------------------------------------------------
Ran 556 tests in 22.204s

FAILED (failures=4, skipped=2)
py312: exit 1 (22.51 seconds) /tmp/autopep8> python test/test_autopep8.py pid=287617
.pkg: _exit> python /usr/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta
  py312: FAIL code 1 (35.39=setup[12.89]+cmd[22.51] seconds)
  evaluation failed :( (35.50 seconds)

Could you please add Python 3.12 support?

Your Environment

hhatto commented 9 months ago

related issue: https://github.com/PyCQA/pycodestyle/issues/1204

hhatto commented 4 months ago

This issue has been resolved in autopep8 version 2.1.0.