fix: treat EOF on stdin as 'quit' in --interactive prompt - #2653
Open
Eljees wants to merge 1 commit into
Open
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1897.
isort --interactiveloops oninput()insideask_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()raisesEOFErrorand isort prints an "unrecoverable exception" traceback. The reproduction is not Windows-specific: the same happens on Linux withisort --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.inputto raiseEOFErrorand asserts a cleanSystemExit; it fails onmain(theEOFErrorpropagates) and passes with the fix. The rest oftests/unit/test_format.pyis unchanged and green.