Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with Black 24.2.1 #553

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"""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
Loading