Skip to content

Commit

Permalink
Remove second pass in the stability checker
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunn1313 committed Nov 18, 2021
1 parent 0d1b957 commit dd08fb1
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/black/__init__.py
Expand Up @@ -906,17 +906,7 @@ def check_stability_and_equivalence(
content differently.
"""
assert_equivalent(src_contents, dst_contents)

# Forced second pass to work around optional trailing commas (becoming
# forced trailing commas on pass 2) interacting differently with optional
# parentheses. Admittedly ugly.
dst_contents_pass2 = format_str(dst_contents, mode=mode)
if dst_contents != dst_contents_pass2:
dst_contents = dst_contents_pass2
assert_equivalent(src_contents, dst_contents, pass_num=2)
assert_stable(src_contents, dst_contents, mode=mode)
# Note: no need to explicitly call `assert_stable` if `dst_contents` was
# the same as `dst_contents_pass2`.
assert_stable(src_contents, dst_contents, mode=mode)


def format_file_contents(src_contents: str, *, fast: bool, mode: Mode) -> FileContent:
Expand Down Expand Up @@ -1282,7 +1272,7 @@ def get_imports_from_children(children: List[LN]) -> Generator[str, None, None]:
return imports


def assert_equivalent(src: str, dst: str, *, pass_num: int = 1) -> None:
def assert_equivalent(src: str, dst: str) -> None:
"""Raise AssertionError if `src` and `dst` aren't equivalent."""
try:
src_ast = parse_ast(src)
Expand All @@ -1296,7 +1286,7 @@ def assert_equivalent(src: str, dst: str, *, pass_num: int = 1) -> None:
except Exception as exc:
log = dump_to_file("".join(traceback.format_tb(exc.__traceback__)), dst)
raise AssertionError(
f"INTERNAL ERROR: Black produced invalid code on pass {pass_num}: {exc}. "
f"INTERNAL ERROR: Black produced invalid code: {exc}. "
"Please report a bug on https://github.com/psf/black/issues. "
f"This invalid output might be helpful: {log}"
) from None
Expand All @@ -1307,7 +1297,7 @@ def assert_equivalent(src: str, dst: str, *, pass_num: int = 1) -> None:
log = dump_to_file(diff(src_ast_str, dst_ast_str, "src", "dst"))
raise AssertionError(
"INTERNAL ERROR: Black produced code that is not equivalent to the"
f" source on pass {pass_num}. Please report a bug on "
f" source. Please report a bug on "
f"https://github.com/psf/black/issues. This diff might be helpful: {log}"
) from None

Expand Down

0 comments on commit dd08fb1

Please sign in to comment.