Skip to content
Myr

Do not suppress EOFError/KeyboardInterrupt when standalone is disabled

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Raise Abort() exception in a chain with the original exception.

authored by Albert Tugushev · committed by David Lord · parent df9ad40 · Browse files · 3 files+16 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+16 added−2 removed

  • tests:+12 added−0 removed
  • other:+4 added−2 removed

3 files+16 added−2 removed

modified:src/click/core.py+2 added-2 removed
1084 unmodified lines
1085 # chained commands which all returned `None` -- so it's not1086 # even always obvious that `rv` indicates success/failure1087 # by its truthiness/falsiness1088 ctx.exit()1089 except (EOFError, KeyboardInterrupt):1089 except (EOFError, KeyboardInterrupt) as e:1090 echo(file=sys.stderr)1091 raise Abort() from None1091 raise Abort() from e1092 except ClickException as e:1093 if not standalone_mode:1094 raise1095 e.show()
1945 unmodified lines
modified:tests/test_commands.py+12 added
395 unmodified lines
396 pass397398 runner.invoke(group, ["command1"])399 assert opt_prefixes == {"-", "--", "~", "+"}400401402@pytest.mark.parametrize("exc", (EOFError, KeyboardInterrupt))403def test_abort_exceptions_with_disabled_standalone_mode(runner, exc):404 @click.command()405 def cli():406 raise exc("catch me!")407408 rv = runner.invoke(cli, standalone_mode=False)409 assert rv.exit_code == 1410 assert isinstance(rv.exception.__cause__, exc)411 assert rv.exception.__cause__.args == ("catch me!",)
modified:CHANGES.rst+2 added
16 unmodified lines
17- Improve responsiveness of ``click.clear()``. :issue:`2284`18- Improve command name detection when using Shiv or PEX. :issue:`2332`19- Avoid showing empty lines if command help text is empty. :issue:`2368`20- ZSH completion script works when loaded from ``fpath``. :issue:`2344`.21- ``EOFError`` and ``KeyboardInterrupt`` tracebacks are not suppressed when22 ``standalone_mode`` is disabled. :issue:`2380`232425Version 8.1.326-------------
1040 unmodified lines