← Back to Pull requests

Fix compatibility with black≥26.5 #65

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Jul 14, 2026 10:25 UTC
Author

The black.parsing.SourceASTParseError exception type was split out from black.parsing.ASTSafetyError in black 26.5.0, https://github.com/psf/black/pull/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 ==========================================================================

Diff: 650 lines (+487 / -163) across 8 files Reviewer: musicinmybrain Review duration: 200746m
All Vouch review confidence checks passed
Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.59 · 650 lines diff across 8 files
0.59
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
44%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.388
Shallow Review Depth shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #65"
general weight: 0.35
Assignees
Unassigned
Labels
risk: low confidence: 44.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 59% (MEDIUM) · Higher = larger blast radius
59%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 44.7% · Lower = rushed or shallow review
44.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 32.6% · Safe to merge
32.6%