From 2918ea3b079bbb617b2f9f0d5bc0b84fde04e48e Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 23 Feb 2022 18:20:59 -0800 Subject: [PATCH 1/1] Format ourselves in preview mode (#2889) --- pyproject.toml | 5 ++++- src/black/__init__.py | 8 ++++---- tests/test_ipynb.py | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ec61779..d937374 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,10 @@ extend-exclude = ''' | profiling )/ ''' - +# We use preview style for formatting Black itself. If you +# want stable formatting across releases, you should keep +# this off. +preview = true # Build system information below. # NOTE: You don't need this in your own Black configuration. diff --git a/src/black/__init__.py b/src/black/__init__.py index b7bf822..c1b9895 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -1358,10 +1358,10 @@ def assert_equivalent(src: str, dst: str) -> None: src_ast = parse_ast(src) except Exception as exc: raise AssertionError( - f"cannot use --safe with this file; failed to parse source file AST: " + "cannot use --safe with this file; failed to parse source file AST: " f"{exc}\n" - f"This could be caused by running Black with an older Python version " - f"that does not support new syntax used in your source file." + "This could be caused by running Black with an older Python version " + "that does not support new syntax used in your source file." ) from exc try: @@ -1380,7 +1380,7 @@ def assert_equivalent(src: str, dst: str) -> 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. Please report a bug on " + " source. Please report a bug on " f"https://github.com/psf/black/issues. This diff might be helpful: {log}" ) from None diff --git a/tests/test_ipynb.py b/tests/test_ipynb.py index 473047a..b534d77 100644 --- a/tests/test_ipynb.py +++ b/tests/test_ipynb.py @@ -415,7 +415,7 @@ def test_ipynb_diff_with_change() -> None: f"--config={EMPTY_CONFIG}", ], ) - expected = "@@ -1,3 +1,3 @@\n %%time\n \n-print('foo')\n" '+print("foo")\n' + expected = "@@ -1,3 +1,3 @@\n %%time\n \n-print('foo')\n+print(\"foo\")\n" assert expected in result.output @@ -494,7 +494,7 @@ def test_ipynb_flag(tmp_path: pathlib.Path) -> None: f"--config={EMPTY_CONFIG}", ], ) - expected = "@@ -1,3 +1,3 @@\n %%time\n \n-print('foo')\n" '+print("foo")\n' + expected = "@@ -1,3 +1,3 @@\n %%time\n \n-print('foo')\n+print(\"foo\")\n" assert expected in result.output -- 2.39.5