From 8b318e9b9400f58f0fb369744f3ca9bc02ff06c7 Mon Sep 17 00:00:00 2001 From: Sergio Acereda Date: Tue, 11 Mar 2025 12:17:58 +0100 Subject: [PATCH 1/5] Write unchanged content to stdout when excluding formating from stdin --- src/black/__init__.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/black/__init__.py b/src/black/__init__.py index 93a08a8d88a..318b602d840 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -683,13 +683,12 @@ def main( # noqa: C901 except GitWildMatchPatternError: ctx.exit(1) - path_empty( - sources, - "No Python files are present to be formatted. Nothing to do 😴", - quiet, - verbose, - ctx, - ) + if not sources: + if verbose or not quiet: + out("No Python files are present to be formatted. Nothing to do 😴") + if "-" in src: + sys.stdout.write(sys.stdin.read()) + ctx.exit(0) if len(sources) == 1: reformat_one( @@ -822,18 +821,6 @@ def get_sources( return sources -def path_empty( - src: Sized, msg: str, quiet: bool, verbose: bool, ctx: click.Context -) -> None: - """ - Exit if there is no `src` provided for formatting - """ - if not src: - if verbose or not quiet: - out(msg) - ctx.exit(0) - - def reformat_code( content: str, fast: bool, From 214b9be9fc63817e3ce6d8030d0c473957426c68 Mon Sep 17 00:00:00 2001 From: Sergio Acereda Date: Mon, 20 Oct 2025 16:01:50 +0200 Subject: [PATCH 2/5] Add changelog entry for PR #4610 --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 262d42e3c01..044a5076bd2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -62,6 +62,7 @@ - Vim: Warn on unsupported Vim and Python versions independently (#4772) - Vim: Print the import paths when importing black fails (#4675) - Vim: Fix handling of virtualenvs that have a different Python version (#4675) +- Write unchanged content to stdout when excluding formating from stdin using pipes (#4609) ### Documentation From 6b19efb7b2d629584d83cdacaf54a0ad73fb98cc Mon Sep 17 00:00:00 2001 From: Sergio Acereda Date: Mon, 20 Oct 2025 16:06:51 +0200 Subject: [PATCH 3/5] From 025659669b67a51a916d2388dce4a825d5d0e1c0 Mon Sep 17 00:00:00 2001 From: cobalt <61329810+cobaltt7@users.noreply.github.com> Date: Mon, 20 Oct 2025 09:31:43 -0500 Subject: [PATCH 4/5] Move changelog entry to Output section --- CHANGES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 044a5076bd2..cb71e3f4ec4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -45,6 +45,9 @@ +- Write unchanged content to stdout when excluding formating from stdin using pipes + (#4610) + ### _Blackd_ @@ -62,7 +65,6 @@ - Vim: Warn on unsupported Vim and Python versions independently (#4772) - Vim: Print the import paths when importing black fails (#4675) - Vim: Fix handling of virtualenvs that have a different Python version (#4675) -- Write unchanged content to stdout when excluding formating from stdin using pipes (#4609) ### Documentation From 12bf3df96614c830c6c9aef83d78ddb01cafea3a Mon Sep 17 00:00:00 2001 From: cobalt <61329810+cobaltt7@users.noreply.github.com> Date: Mon, 20 Oct 2025 09:35:26 -0500 Subject: [PATCH 5/5] Remove unused import --- src/black/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/black/__init__.py b/src/black/__init__.py index be2b1f35a2c..c88aa4ef6c7 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -11,7 +11,6 @@ Iterator, MutableMapping, Sequence, - Sized, ) from contextlib import contextmanager from dataclasses import replace