Skip to content

Test regressions with black-24.3.0 #57

Closed
@bnavigator

Description

@bnavigator

Black 24.3 introduced a new error message:

https://github.com/psf/black/blob/main/CHANGES.md#2430

[   36s] =================================== FAILURES ===================================
[   36s] ___________________ test_pylsp_format_document_syntax_error ____________________
[   36s] 
[   36s] src = '    x = 1+2\n', dst = 'x = 1 + 2\n'
[   36s] 
[   36s]     def assert_equivalent(src: str, dst: str) -> None:
[   36s]         """Raise AssertionError if `src` and `dst` aren't equivalent."""
[   36s]         try:
[   36s] >           src_ast = parse_ast(src)
[   36s] 
[   36s] /usr/lib/python3.9/site-packages/black/__init__.py:1526: 
[   36s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   36s] 
[   36s] src = '    x = 1+2\n'
[   36s] 
[   36s]     def parse_ast(src: str) -> ast.AST:
[   36s]         # TODO: support Python 4+ ;)
[   36s]         versions = [(3, minor) for minor in range(3, sys.version_info[1] + 1)]
[   36s]     
[   36s]         first_error = ""
[   36s]         for version in sorted(versions, reverse=True):
[   36s]             try:
[   36s]                 return _parse_single_version(src, version, type_comments=True)
[   36s]             except SyntaxError as e:
[   36s]                 if not first_error:
[   36s]                     first_error = str(e)
[   36s]     
[   36s]         # Try to parse without type comments
[   36s]         for version in sorted(versions, reverse=True):
[   36s]             try:
[   36s]                 return _parse_single_version(src, version, type_comments=False)
[   36s]             except SyntaxError:
[   36s]                 pass
[   36s]     
[   36s] >       raise SyntaxError(first_error)
[   36s] E       SyntaxError: unexpected indent (<unknown>, line 1)
[   36s] 
[   36s] /usr/lib/python3.9/site-packages/black/parsing.py:148: SyntaxError
[   36s] 
[   36s] The above exception was the direct cause of the following exception:
[   36s] 
[   36s] config = <pylsp.config.config.Config object at 0x7f31105ea3d0>
[   36s] invalid_document = <pylsp.workspace.Document object at 0x7f31105ea220>
[   36s] 
[   36s]     def test_pylsp_format_document_syntax_error(config, invalid_document):
[   36s] >       result = pylsp_format_document(config, invalid_document)
[   36s] 
[   36s] tests/test_plugin.py:179: 
[   36s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   36s] ../../BUILDROOT/python-python-lsp-black-2.0.0-0.x86_64/usr/lib/python3.9/site-packages/pylsp_black/plugin.py:38: in pylsp_format_document
[   36s]     return format_document(config, document)
[   36s] ../../BUILDROOT/python-python-lsp-black-2.0.0-0.x86_64/usr/lib/python3.9/site-packages/pylsp_black/plugin.py:73: in format_document
[   36s]     formatted_text = format_text(text=text, config=config, lines=lines)
[   36s] ../../BUILDROOT/python-python-lsp-black-2.0.0-0.x86_64/usr/lib/python3.9/site-packages/pylsp_black/plugin.py:114: in format_text
[   36s]     formatted_text = black.format_file_contents(
[   36s] /usr/lib/python3.9/site-packages/black/__init__.py:1083: in format_file_contents
[   36s]     check_stability_and_equivalence(
[   36s] /usr/lib/python3.9/site-packages/black/__init__.py:1057: in check_stability_and_equivalence
[   36s]     assert_equivalent(src_contents, dst_contents)
[   36s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   36s] 
[   36s] src = '    x = 1+2\n', dst = 'x = 1 + 2\n'
[   36s] 
[   36s]     def assert_equivalent(src: str, dst: str) -> None:
[   36s]         """Raise AssertionError if `src` and `dst` aren't equivalent."""
[   36s]         try:
[   36s]             src_ast = parse_ast(src)
[   36s]         except Exception as exc:
[   36s] >           raise ASTSafetyError(
[   36s]                 "cannot use --safe with this file; failed to parse source file AST: "
[   36s]                 f"{exc}\n"
[   36s]                 "This could be caused by running Black with an older Python version "
[   36s]                 "that does not support new syntax used in your source file."
[   36s]             ) from exc
[   36s] E           black.parsing.ASTSafetyError: cannot use --safe with this file; failed to parse source file AST: unexpected indent (<unknown>, line 1)
[   36s] E           This could be caused by running Black with an older Python version that does not support new syntax used in your source file.
[   36s] 
[   36s] /usr/lib/python3.9/site-packages/black/__init__.py:1528: ASTSafetyError
[   36s] _____________________ test_pylsp_format_range_syntax_error _____________________
[   36s] 
[   36s] src = '    x = 1+2\n', dst = 'x = 1 + 2\n'
[   36s] 
[   36s]     def assert_equivalent(src: str, dst: str) -> None:
[   36s]         """Raise AssertionError if `src` and `dst` aren't equivalent."""
[   36s]         try:
[   36s] >           src_ast = parse_ast(src)
[   36s] 
[   36s] /usr/lib/python3.9/site-packages/black/__init__.py:1526: 
[   36s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   36s] 
[   36s] src = '    x = 1+2\n'
[   36s] 
[   36s]     def parse_ast(src: str) -> ast.AST:
[   36s]         # TODO: support Python 4+ ;)
[   36s]         versions = [(3, minor) for minor in range(3, sys.version_info[1] + 1)]
[   36s]     
[   36s]         first_error = ""
[   36s]         for version in sorted(versions, reverse=True):
[   36s]             try:
[   36s]                 return _parse_single_version(src, version, type_comments=True)
[   36s]             except SyntaxError as e:
[   36s]                 if not first_error:
[   36s]                     first_error = str(e)
[   36s]     
[   36s]         # Try to parse without type comments
[   36s]         for version in sorted(versions, reverse=True):
[   36s]             try:
[   36s]                 return _parse_single_version(src, version, type_comments=False)
[   36s]             except SyntaxError:
[   36s]                 pass
[   36s]     
[   36s] >       raise SyntaxError(first_error)
[   36s] E       SyntaxError: unexpected indent (<unknown>, line 1)
[   36s] 
[   36s] /usr/lib/python3.9/site-packages/black/parsing.py:148: SyntaxError
[   36s] 
[   36s] The above exception was the direct cause of the following exception:
[   36s] 
[   36s] config = <pylsp.config.config.Config object at 0x7f31105ae910>
[   36s] invalid_document = <pylsp.workspace.Document object at 0x7f31105cd0a0>
[   36s] 
[   36s]     def test_pylsp_format_range_syntax_error(config, invalid_document):
[   36s]         range = {"start": {"line": 0, "character": 0}, "end": {"line": 1, "character": 0}}
[   36s]     
[   36s] >       result = pylsp_format_range(config, invalid_document, range=range)
[   36s] 
[   36s] tests/test_plugin.py:253: 
[   36s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   36s] ../../BUILDROOT/python-python-lsp-black-2.0.0-0.x86_64/usr/lib/python3.9/site-packages/pylsp_black/plugin.py:46: in pylsp_format_range
[   36s]     return format_document(config, document, range)
[   36s] ../../BUILDROOT/python-python-lsp-black-2.0.0-0.x86_64/usr/lib/python3.9/site-packages/pylsp_black/plugin.py:73: in format_document
[   36s]     formatted_text = format_text(text=text, config=config, lines=lines)
[   36s] ../../BUILDROOT/python-python-lsp-black-2.0.0-0.x86_64/usr/lib/python3.9/site-packages/pylsp_black/plugin.py:114: in format_text
[   36s]     formatted_text = black.format_file_contents(
[   36s] /usr/lib/python3.9/site-packages/black/__init__.py:1083: in format_file_contents
[   36s]     check_stability_and_equivalence(
[   36s] /usr/lib/python3.9/site-packages/black/__init__.py:1057: in check_stability_and_equivalence
[   36s]     assert_equivalent(src_contents, dst_contents)
[   36s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   36s] 
[   36s] src = '    x = 1+2\n', dst = 'x = 1 + 2\n'
[   36s] 
[   36s]     def assert_equivalent(src: str, dst: str) -> None:
[   36s]         """Raise AssertionError if `src` and `dst` aren't equivalent."""
[   36s]         try:
[   36s]             src_ast = parse_ast(src)
[   36s]         except Exception as exc:
[   36s] >           raise ASTSafetyError(
[   36s]                 "cannot use --safe with this file; failed to parse source file AST: "
[   36s]                 f"{exc}\n"
[   36s]                 "This could be caused by running Black with an older Python version "
[   36s]                 "that does not support new syntax used in your source file."
[   36s]             ) from exc
[   36s] E           black.parsing.ASTSafetyError: cannot use --safe with this file; failed to parse source file AST: unexpected indent (<unknown>, line 1)
[   36s] E           This could be caused by running Black with an older Python version that does not support new syntax used in your source file.
[   36s] 
[   36s] /usr/lib/python3.9/site-packages/black/__init__.py:1528: ASTSafetyError
[   36s] =============================== warnings summary ===============================
[   36s] tests/test_plugin.py:8
[   36s]   /home/abuild/rpmbuild/BUILD/python-lsp-black-2.0.0/tests/test_plugin.py:8: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
[   36s]     import pkg_resources
[   36s] 
[   36s] -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
[   36s] =========================== short test summary info ============================
[   36s] FAILED tests/test_plugin.py::test_pylsp_format_document_syntax_error - black....
[   36s] FAILED tests/test_plugin.py::test_pylsp_format_range_syntax_error - black.par...
[   36s] =================== 2 failed, 19 passed, 1 warning in 0.62s ====================

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions