diff --git a/prompt_toolkit/input/vt100.py b/prompt_toolkit/input/vt100.py index 1c38333a9..1ef9af35f 100644 --- a/prompt_toolkit/input/vt100.py +++ b/prompt_toolkit/input/vt100.py @@ -48,13 +48,13 @@ def __init__(self, stdin: TextIO) -> None: try: # This should not raise, but can return 0. stdin.fileno() - except io.UnsupportedOperation: + except io.UnsupportedOperation as e: if "idlelib.run" in sys.modules: raise io.UnsupportedOperation( "Stdin is not a terminal. Running from Idle is not supported." - ) + ) from e else: - raise io.UnsupportedOperation("Stdin is not a terminal.") + raise io.UnsupportedOperation("Stdin is not a terminal.") from e # Even when we have a file descriptor, it doesn't mean it's a TTY. # Normally, this requires a real TTY device, but people instantiate diff --git a/prompt_toolkit/key_binding/bindings/named_commands.py b/prompt_toolkit/key_binding/bindings/named_commands.py index 0395785c7..74c81a03d 100644 --- a/prompt_toolkit/key_binding/bindings/named_commands.py +++ b/prompt_toolkit/key_binding/bindings/named_commands.py @@ -55,8 +55,8 @@ def get_by_name(name: str) -> Binding: """ try: return _readline_commands[name] - except KeyError: - raise KeyError("Unknown Readline command: %r" % name) + except KeyError as e: + raise KeyError("Unknown Readline command: %r" % name) from e # diff --git a/prompt_toolkit/layout/layout.py b/prompt_toolkit/layout/layout.py index 79cf7f947..31f3c429f 100644 --- a/prompt_toolkit/layout/layout.py +++ b/prompt_toolkit/layout/layout.py @@ -59,10 +59,10 @@ def __init__( if focused_element is None: try: self._stack.append(next(self.find_all_windows())) - except StopIteration: + except StopIteration as e: raise InvalidLayoutError( "Invalid layout. The layout does not contain any Window object." - ) + ) from e else: self.focus(focused_element)