Skip to content

Commit

Permalink
Merge pull request #553 from akaihola/black-24.2.1-compat
Browse files Browse the repository at this point in the history
Fix compatibility with Black 24.2.1
  • Loading branch information
akaihola authored Mar 11, 2024
2 parents 1a0619c + 5d3d382 commit 628c8c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ Added

Fixed
-----
- Black 24.2 compatibility by using the new `darkgraylib.files.find_project_root`
- Black 24.2.0 compatibility by using the new `darkgraylib.files.find_project_root`
instead of the implementation in Black.
- Black 24.2.1 compatibility by detecting the new `black.parsing.ASTSafetyError` instead
of `AssertionError` when Black>=24.2.1 is in use.


1.7.3_ - 2024-02-27
Expand Down
9 changes: 8 additions & 1 deletion src/darker/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
from darker.utils import debug_dump
from darkgraylib.utils import DiffChunk, TextDocument

try:
# Black 24.2.1 and later
from black.parsing import ASTSafetyError # pylint: disable=ungrouped-imports

Check failure on line 12 in src/darker/verification.py

View workflow job for this annotation

GitHub Actions / Mypy

src/darker/verification.py#L12

Module "black.parsing" has no attribute "ASTSafetyError" [attr-defined]
except ImportError:
# Black 24.2.0 and earlier
ASTSafetyError = AssertionError


class NotEquivalentError(Exception):
"""Exception to raise if two ASTs being compared are not equivalent"""
Expand Down Expand Up @@ -65,7 +72,7 @@ def verify_ast_unchanged(
"""Verify that source code parses to the same AST before and after reformat"""
try:
assert_equivalent(edited_to_file.string, reformatted.string)
except AssertionError as exc_info:
except ASTSafetyError as exc_info:
debug_dump(black_chunks, edited_linenums)
raise NotEquivalentError() from exc_info

Expand Down

0 comments on commit 628c8c5

Please sign in to comment.