Add type annotations for instance attributes in `exceptions` (#3453)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Rowlando13 · committed by GitHub · parents 18c2451, 9207bdc · Browse files · 1 file·+42 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+42 added−11 removed
- other:+42 added−11 removed
Provenance
- Commit
2b4d35b- Tree
8490982- Author
Rowlando13 <67291205+Rowlando13@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
18c2451- Parent 2
9207bdc
1 file changed+42 added−11 removed
modified:src/click/exceptions.py+42 added-11 removed
34 unmodified lines35 class ClickException(Exception):36 """An exception that Click can handle and show to the user."""37 38 #: The exit code for this exception.39- exit_code = 139+ exit_code: t.ClassVar[int] = 140 41+ show_color: t.Final[bool | None]42+ message: t.Final[str]43+44 def __init__(self, message: str) -> None:45 super().__init__(message)46 # The context will be removed by the time we print the message, so cache47 # the color settings here to be used later on (in `show`)45- self.show_color: bool | None = resolve_color_default()48+ self.show_color = resolve_color_default()49 self.message = message50 51 def format_message(self) -> str:52 return self.message20 unmodified lines73 :param ctx: optionally the context that caused this error. Click will74 fill in the context automatically in some situations.75 """76 74- exit_code = 277+ exit_code: t.ClassVar[int] = 278 79+ ctx: Context | None80+ cmd: t.Final[Command | None]81+82 def __init__(self, message: str, ctx: Context | None = None) -> None:83 super().__init__(message)84 self.ctx = ctx79- self.cmd: Command | None = self.ctx.command if self.ctx else None85+ self.cmd = self.ctx.command if self.ctx else None86 87 def show(self, file: t.IO[t.Any] | None = None) -> None:88 if file is None:89 file = get_text_stderr()38 unmodified lines128 a string it's used as such, if it's a list then129 each item is quoted and separated.130 """131 132+ param: Parameter | None133+ param_hint: cabc.Sequence[str] | str | None134+135 def __init__(136 self,137 message: str,138 ctx: Context | None = None,28 unmodified lines167 the given `param`. Valid values are ``'parameter'``,168 ``'option'`` or ``'argument'``.169 """170 171+ param_type: t.Final[str | None]172+173 def __init__(174 self,175 message: str | None = None,176 ctx: Context | None = None,57 unmodified lines234 235 .. versionadded:: 4.0236 """237 238+ option_name: t.Final[str]239+ possibilities: t.Final[list[str] | None]240+241 def __init__(242 self,243 option_name: str,244 message: str | None = None,4 unmodified lines249 message = _("No such option {name!r}.").format(name=option_name)250 251 super().__init__(message, ctx)252 self.option_name = option_name239- self.possibilities: list[str] | None = None253+254 if possibilities:255 from difflib import get_close_matches256 243- self.possibilities = get_close_matches(option_name, possibilities)257+ possibilities_ = get_close_matches(option_name, possibilities)258+ else:259+ possibilities_ = None260+ self.possibilities = possibilities_261 262 def format_message(self) -> str:263 if not self.possibilities:264 return self.message5 unmodified lines270 271 .. versionadded:: 8.4.0272 """273 274+ command_name: t.Final[str]275+ possibilities: t.Final[list[str] | None]276+277 def __init__(278 self,279 command_name: str,280 message: str | None = None,4 unmodified lines285 message = _("No such command {name!r}.").format(name=command_name)286 287 super().__init__(message, ctx)288 self.command_name = command_name269- self.possibilities: list[str] | None = None289+290 if possibilities:291 from difflib import get_close_matches292 273- self.possibilities = get_close_matches(command_name, possibilities)293+ possibilities_ = get_close_matches(command_name, possibilities)294+ else:295+ possibilities_ = None296+ self.possibilities = possibilities_297 298 def format_message(self) -> str:299 if not self.possibilities:300 return self.message9 unmodified lines310 311 :param option_name: the name of the option being used incorrectly.312 """313 314+ option_name: t.Final[str]315+316 def __init__(317 self, option_name: str, message: str, ctx: Context | None = None318 ) -> None:319 super().__init__(message, ctx)9 unmodified lines329 """330 331 332 class NoArgsIsHelpError(UsageError):333+ ctx: Context334+335 def __init__(self, ctx: Context) -> None:309- self.ctx: Context336 super().__init__(ctx.get_help(), ctx=ctx)337 338 def show(self, file: t.IO[t.Any] | None = None) -> None:339 echo(self.format_message(), file=file, err=True, color=self.ctx.color)1 unmodified line341 342 class FileError(ClickException):343 """Raised if a file cannot be opened."""344 345+ ui_filename: t.Final[str]346+ filename: t.Final[str]347+348 def __init__(self, filename: str, hint: str | None = None) -> None:349 if hint is None:350 hint = _("unknown error")351 352 super().__init__(hint)324- self.ui_filename: str = format_filename(filename)353+ self.ui_filename = format_filename(filename)354 self.filename = filename355 356 def format_message(self) -> str:357 return _("Could not open file {filename!r}: {message}").format(13 unmodified lines371 """372 373 __slots__ = ("exit_code",)374 375+ exit_code: t.Final[int]376+377 def __init__(self, code: int = 0) -> None:347- self.exit_code: int = code378+ self.exit_code = code