GeezerVison is showing github.com — Fix compatibility with black≥26.5 by musicinmybrain · Pull Request #65 · python-lsp/python-lsp-black
Conversation
The black.parsing.SourceASTParseError exception type was split out from black.parsing.ASTSafetyError in black 26.5.0, psf/black#5080.
This fixes:
========================================================================================= FAILURES ==========================================================================================
__________________________________________________________________________ test_pylsp_format_document_syntax_error __________________________________________________________________________
> ???
src/black/__init__.py:1636:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E SyntaxError: unexpected indent (<unknown>, line 1)
src/black/parsing.py:162: SyntaxError
During handling of the above exception, another exception occurred:
config = <pylsp.config.config.Config object at 0x7ff7e753de00>, invalid_document = <pylsp.workspace.Document object at 0x7ff7e7545f20>
def test_pylsp_format_document_syntax_error(config, invalid_document):
> result = pylsp_format_document(config, invalid_document)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tests/test_plugin.py:179:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pylsp_black/plugin.py:38: in pylsp_format_document
return format_document(config, document)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pylsp_black/plugin.py:73: in format_document
formatted_text = format_text(text=text, config=config, lines=lines)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pylsp_black/plugin.py:114: in format_text
formatted_text = black.format_file_contents(
src/black/__init__.py:1124: in format_file_contents
???
src/black/__init__.py:1089: in check_stability_and_equivalence
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E black.parsing.SourceASTParseError: cannot use --safe with this file; failed to parse source file AST: unexpected indent (<unknown>, line 1)
E This could be caused by running Black with an older Python version that does not support new syntax used in your source file.
src/black/__init__.py:1638: SourceASTParseError
___________________________________________________________________________ test_pylsp_format_range_syntax_error ____________________________________________________________________________
> ???
src/black/__init__.py:1636:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E SyntaxError: unexpected indent (<unknown>, line 1)
src/black/parsing.py:162: SyntaxError
During handling of the above exception, another exception occurred:
config = <pylsp.config.config.Config object at 0x7ff7e75433e0>, invalid_document = <pylsp.workspace.Document object at 0x7ff7e74d19b0>
def test_pylsp_format_range_syntax_error(config, invalid_document):
range = {"start": {"line": 0, "character": 0}, "end": {"line": 1, "character": 0}}
> result = pylsp_format_range(config, invalid_document, range=range)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tests/test_plugin.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pylsp_black/plugin.py:46: in pylsp_format_range
return format_document(config, document, range)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pylsp_black/plugin.py:73: in format_document
formatted_text = format_text(text=text, config=config, lines=lines)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pylsp_black/plugin.py:114: in format_text
formatted_text = black.format_file_contents(
src/black/__init__.py:1124: in format_file_contents
???
src/black/__init__.py:1089: in check_stability_and_equivalence
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E black.parsing.SourceASTParseError: cannot use --safe with this file; failed to parse source file AST: unexpected indent (<unknown>, line 1)
E This could be caused by running Black with an older Python version that does not support new syntax used in your source file.
src/black/__init__.py:1638: SourceASTParseError
===================================================================================== warnings summary ======================================================================================
tests/test_plugin.py:8
/home/ben/src/forks/python-lsp-black/tests/test_plugin.py:8: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
import pkg_resources
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================== short test summary info ==================================================================================
FAILED tests/test_plugin.py::test_pylsp_format_document_syntax_error - black.parsing.SourceASTParseError: cannot use --safe with this file; failed to parse source file AST: unexpected indent (<unknown>, line 1)
FAILED tests/test_plugin.py::test_pylsp_format_range_syntax_error - black.parsing.SourceASTParseError: cannot use --safe with this file; failed to parse source file AST: unexpected indent (<unknown>, line 1)
========================================================================== 2 failed, 19 passed, 1 warning in 0.38s ==========================================================================
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
djacu
commented
Jul 20, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Carried this downstream in nixpkgs (NixOS/nixpkgs#543713) to unblock python-lsp-black and spyder on black 26.5. It builds cleanly there against black 26.5.1. Would be great to get it merged / into a release. Thanks!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I apologize for not being more responsive.
The reality is that I moved to ruff over black a while ago and have not been using python-lsp-black any longer. That coupled with the Summer vacation is going to delay my reviewing and testing of these PRs.
@ccordoba12 would you have any bandwidth for this?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
haplo
haplo left review comments
At least 1 approving review is required to merge this pull request.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|