Skip to content
Myr

Add type annotations for instance attributes in `exceptions`

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

authored by jorenham · committed by jorenham · parent 648d7c4 · 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

1 file+42 added−11 removed

modified:src/click/exceptions.py+42 added-11 removed
34 unmodified lines
35class ClickException(Exception):36 """An exception that Click can handle and show to the user."""3738 #: The exit code for this exception.39 exit_code = 139 exit_code: t.ClassVar[int] = 14041 show_color: t.Final[bool | None]42 message: t.Final[str]4344 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 = message5051 def format_message(self) -> str:52 return self.message
20 unmodified lines
73 :param ctx: optionally the context that caused this error. Click will74 fill in the context automatically in some situations.75 """7674 exit_code = 277 exit_code: t.ClassVar[int] = 27879 ctx: Context | None80 cmd: t.Final[Command | None]8182 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 None8687 def show(self, file: t.IO[t.Any] | None = None) -> None:88 if file is None:89 file = get_text_stderr()
38 unmodified lines
128 a string it's used as such, if it's a list then129 each item is quoted and separated.130 """131132 param: Parameter | None133 param_hint: cabc.Sequence[str] | str | None134135 def __init__(136 self,137 message: str,138 ctx: Context | None = None,
28 unmodified lines
167 the given `param`. Valid values are ``'parameter'``,168 ``'option'`` or ``'argument'``.169 """170171 param_type: t.Final[str | None]172173 def __init__(174 self,175 message: str | None = None,176 ctx: Context | None = None,
57 unmodified lines
234235 .. versionadded:: 4.0236 """237238 option_name: t.Final[str]239 possibilities: t.Final[list[str] | None]240241 def __init__(242 self,243 option_name: str,244 message: str | None = None,
4 unmodified lines
249 message = _("No such option {name!r}.").format(name=option_name)250251 super().__init__(message, ctx)252 self.option_name = option_name239 self.possibilities: list[str] | None = None253254 if possibilities:255 from difflib import get_close_matches256243 self.possibilities = get_close_matches(option_name, possibilities)257 possibilities_ = get_close_matches(option_name, possibilities)258 else:259 possibilities_ = None260 self.possibilities = possibilities_261262 def format_message(self) -> str:263 if not self.possibilities:264 return self.message
5 unmodified lines
270271 .. versionadded:: 8.4.0272 """273274 command_name: t.Final[str]275 possibilities: t.Final[list[str] | None]276277 def __init__(278 self,279 command_name: str,280 message: str | None = None,
4 unmodified lines
285 message = _("No such command {name!r}.").format(name=command_name)286287 super().__init__(message, ctx)288 self.command_name = command_name269 self.possibilities: list[str] | None = None289290 if possibilities:291 from difflib import get_close_matches292273 self.possibilities = get_close_matches(command_name, possibilities)293 possibilities_ = get_close_matches(command_name, possibilities)294 else:295 possibilities_ = None296 self.possibilities = possibilities_297298 def format_message(self) -> str:299 if not self.possibilities:300 return self.message
9 unmodified lines
310311 :param option_name: the name of the option being used incorrectly.312 """313314 option_name: t.Final[str]315316 def __init__(317 self, option_name: str, message: str, ctx: Context | None = None318 ) -> None:319 super().__init__(message, ctx)
9 unmodified lines
329 """330331332class NoArgsIsHelpError(UsageError):333 ctx: Context334335 def __init__(self, ctx: Context) -> None:309 self.ctx: Context336 super().__init__(ctx.get_help(), ctx=ctx)337338 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 line
341342class FileError(ClickException):343 """Raised if a file cannot be opened."""344345 ui_filename: t.Final[str]346 filename: t.Final[str]347348 def __init__(self, filename: str, hint: str | None = None) -> None:349 if hint is None:350 hint = _("unknown error")351352 super().__init__(hint)324 self.ui_filename: str = format_filename(filename)353 self.ui_filename = format_filename(filename)354 self.filename = filename355356 def format_message(self) -> str:357 return _("Could not open file {filename!r}: {message}").format(
13 unmodified lines
371 """372373 __slots__ = ("exit_code",)374375 exit_code: t.Final[int]376377 def __init__(self, code: int = 0) -> None:347 self.exit_code: int = code378 self.exit_code = code