diff --git a/isort/main.py b/isort/main.py index 9369ddd1..72d95b97 100644 --- a/isort/main.py +++ b/isort/main.py @@ -1059,6 +1059,8 @@ def main(argv: Sequence[str] | None = None, stdin: TextIOWrapper | None = None) file_path = Path(stream_filename) if stream_filename else None if show_files: sys.exit("Error: can't show files for streaming input.") + if config.sort_reexports: + sys.exit("Error: --sort-reexports is not supported with streaming input (stdin).") input_stream = sys.stdin if stdin is None else stdin if check: diff --git a/tests/unit/test_regressions.py b/tests/unit/test_regressions.py index 3291745b..088be9eb 100644 --- a/tests/unit/test_regressions.py +++ b/tests/unit/test_regressions.py @@ -2012,3 +2012,16 @@ def test_comment_on_opening_line_of_aliased_import_does_not_move(): isort.code(short_line, profile="black") == "from mod import attr as alias # type: ignore[attr-defined] # My comment\n" ) + + +def test_sort_reexports_with_stdin_raises_error_issue_2393(): + """Ensure --sort-reexports raises a clear error when used with stdin. + issues #2393 + """ + import io + from isort.main import main as isort_main + + fake_stdin = io.TextIOWrapper(io.BytesIO(b"from test import B, A\n")) + with pytest.raises(SystemExit) as exc_info: + isort_main(argv=["--sort-reexports", "-"], stdin=fake_stdin) + assert exc_info.value.code != 0