Merge pull request #2074 from pallets/except-chain
Before adoption: this commit came in with the history the project adopted, so no landing records it.
use exception chaining
authored by David Lord · committed by GitHub · parents 737cf79, 905b1bf · Browse files · 6 files·+10 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+10 added−10 removed
- other:+10 added−10 removed
Provenance
- Commit
749eab5- Tree
c627de2- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
737cf79- Parent 2
905b1bf
6 files changed+10 added−10 removed
modified:src/click/_termui_impl.py+1 added-1 removed
496 unmodified lines497 )498 except OSError as e:499 raise ClickException(500 _("{editor}: Editing failed: {e}").format(editor=editor, e=e)501- )501+ ) from e502 503 def edit(self, text: t.Optional[t.AnyStr]) -> t.Optional[t.AnyStr]:504 import tempfile505 213 unmodified linesmodified:src/click/core.py+1 added-1 removed
1059 unmodified lines1060 # by its truthiness/falsiness1061 ctx.exit()1062 except (EOFError, KeyboardInterrupt):1063 echo(file=sys.stderr)1064- raise Abort()1064+ raise Abort() from None1065 except ClickException as e:1066 if not standalone_mode:1067 raise1068 e.show()1879 unmodified linesmodified:src/click/decorators.py+1 added-1 removed
378 unmodified lines379 except metadata.PackageNotFoundError: # type: ignore380 raise RuntimeError(381 f"{package_name!r} is not installed. Try passing"382 " 'package_name' instead."383- )383+ ) from None384 385 if version is None:386 raise RuntimeError(387 f"Could not determine the version for {package_name!r} automatically."49 unmodified linesmodified:src/click/globals.py+2 added-2 removed
34 unmodified lines35 :exc:`RuntimeError`.36 """37 try:38 return t.cast("Context", _local.stack[-1])39- except (AttributeError, IndexError):39+ except (AttributeError, IndexError) as e:40 if not silent:41- raise RuntimeError("There is no active click context.")41+ raise RuntimeError("There is no active click context.") from e42 43 return None44 45 24 unmodified linesmodified:src/click/termui.py+4 added-4 removed
145 unmodified lines146 # Allegedly this behavior is inherited from getpass(3).147 # A doc bug has been filed at https://bugs.python.org/issue24711148 if hide_input:149 echo(None, err=err)150- raise Abort()150+ raise Abort() from None151 152 if value_proc is None:153 value_proc = convert_type(type, default)154 78 unmodified lines233 # coloring through colorama on Windows234 echo(prompt, nl=False, err=err)235 value = visible_prompt_func("").lower().strip()236 except (KeyboardInterrupt, EOFError):237- raise Abort()237+ raise Abort() from None238 if value in ("y", "yes"):239 rv = True240 elif value in ("n", "no"):241 rv = False338 unmodified lines580 if fg:581 try:582 bits.append(f"\033[{_interpret_color(fg)}m")583 except KeyError:584- raise TypeError(f"Unknown color {fg!r}")584+ raise TypeError(f"Unknown color {fg!r}") from None585 586 if bg:587 try:588 bits.append(f"\033[{_interpret_color(bg, 10)}m")589 except KeyError:590- raise TypeError(f"Unknown color {bg!r}")590+ raise TypeError(f"Unknown color {bg!r}") from None591 592 if bold is not None:593 bits.append(f"\033[{1 if bold else 22}m")594 if dim is not None:213 unmodified linesmodified:src/click/utils.py+1 added-1 removed
152 unmodified lines153 )154 except OSError as e: # noqa: E402155 from .exceptions import FileError156 157- raise FileError(self.name, hint=e.strerror)157+ raise FileError(self.name, hint=e.strerror) from e158 self._f = rv159 return rv160 161 def close(self) -> None:418 unmodified lines