Skip to content

fix: treat EOF on stdin as 'quit' in --interactive prompt - #2653

Open
Eljees wants to merge 1 commit into
PyCQA:mainfrom
Eljees:fix/1897-interactive-eof
Open

fix: treat EOF on stdin as 'quit' in --interactive prompt#2653
Eljees wants to merge 1 commit into
PyCQA:mainfrom
Eljees:fix/1897-interactive-eof

Conversation

@Eljees

@Eljees Eljees commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #1897.

isort --interactive loops on input() inside ask_whether_to_apply_changes_to_file, so when standard input is closed or has no more data — stdin redirected from an empty source, or a terminal wrapper that doesn't provide a readable stdin, as in the Git-Bash report — input() raises EOFError and isort prints an "unrecoverable exception" traceback. The reproduction is not Windows-specific: the same happens on Linux with isort --interactive < /dev/null.

Since no answer can ever arrive once stdin is exhausted, the prompt now treats EOF the same way as an explicit quit: exit cleanly with a short explanatory message instead of a traceback.

The regression test patches builtins.input to raise EOFError and asserts a clean SystemExit; it fails on main (the EOFError propagates) and passes with the fix. The rest of tests/unit/test_format.py is unchanged and green.

ask_whether_to_apply_changes_to_file loops on input(), so when standard
input is closed or exhausted (e.g. stdin redirected, or a terminal that
does not provide a readable stdin), input() raises EOFError and isort
reports an 'unrecoverable exception' traceback. Exit cleanly with an
explanatory message instead, the same way an explicit 'quit' answer
stops processing.

Fixes PyCQA#1897

Signed-off-by: Eljees <3.14hell@gmail.com>
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.37%. Comparing base (131f4ad) to head (8721a1b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2653   +/-   ##
=======================================
  Coverage   99.37%   99.37%           
=======================================
  Files          41       41           
  Lines        3181     3184    +3     
  Branches      686      686           
=======================================
+ Hits         3161     3164    +3     
  Misses         12       12           
  Partials        8        8           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--interactive causes unrecoverable exception

1 participant