Skip to content
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
2 changes: 2 additions & 0 deletions isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion tests/unit/test_regressions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""A growing set of tests designed to ensure isort doesn't have regressions in new versions"""

from io import StringIO
from io import BytesIO, StringIO, TextIOWrapper

import pytest

import isort
from isort.main import main


def test_isort_duplicating_comments_issue_1264():
Expand Down Expand Up @@ -2012,3 +2013,11 @@ 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."""
fake_stdin = TextIOWrapper(BytesIO(b"from test import B, A\n"))
with pytest.raises(SystemExit) as exc_info:
main(argv=["--sort-reexports", "-"], stdin=fake_stdin)
assert exc_info.value.code != 0
Loading