Skip to content
Myr

Add type annotations for instance attributes in `testing` (#3451)

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

authored by Rowlando13 · committed by GitHub · parents e169e82, e39679a · Browse files · 1 file+48 added−15 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+48 added−15 removed

  • other:+48 added−15 removed

1 file+48 added−15 removed

modified:src/click/testing.py+48 added-15 removed
20 unmodified lines
21 from _typeshed import ReadableBuffer2223 from .core import Command2425CaptureMode = t.Literal["sys", "fd"]25CaptureMode: t.TypeAlias = t.Literal["sys", "fd"]26ExceptionInfo: t.TypeAlias = tuple[type[BaseException], BaseException, TracebackType]272829class EchoingStdin:30 _input: t.BinaryIO31 _output: t.BinaryIO32 _paused: bool3334 def __init__(self, input: t.BinaryIO, output: t.BinaryIO) -> None:35 self._input = input36 self._output = output37 self._paused = False
26 unmodified lines
64 return repr(self._input)656667@contextlib.contextmanager63def _pause_echo(stream: EchoingStdin | None) -> cabc.Iterator[None]:68def _pause_echo(stream: EchoingStdin | None) -> cabc.Generator[None]:69 if stream is None:70 yield71 else:72 stream._paused = True
11 unmodified lines
8485 .. versionadded:: 8.4.086 """8788 _targetfd: int89 saved_fd: int90 _tmpfile: t.BinaryIO | None9192 def __init__(self, targetfd: int) -> None:93 self._targetfd = targetfd85 self.saved_fd: int = -186 self._tmpfile: t.BinaryIO | None = None94 self.saved_fd = -195 self._tmpfile = None9697 def start(self) -> None:98 self.saved_fd = os.dup(self._targetfd)99 self._tmpfile = tempfile.TemporaryFile(buffering=0)
16 unmodified lines
116117 .. versionadded:: 8.2118 """119120 copy_to: io.BytesIO121122 def __init__(self, copy_to: io.BytesIO) -> None:123 super().__init__()124 self.copy_to = copy_to125
13 unmodified lines
139140 .. versionadded:: 8.2141 """142143 output: io.BytesIO144 stdout: BytesIOCopy145 stderr: BytesIOCopy146147 def __init__(self) -> None:133 self.output: io.BytesIO = io.BytesIO()134 self.stdout: io.BytesIO = BytesIOCopy(copy_to=self.output)135 self.stderr: io.BytesIO = BytesIOCopy(copy_to=self.output)148 self.output = io.BytesIO()149 self.stdout = BytesIOCopy(copy_to=self.output)150 self.stderr = BytesIOCopy(copy_to=self.output)151152153class _NamedTextIOWrapper(io.TextIOWrapper):154 """A :class:`~io.TextIOWrapper` with custom ``name`` and ``mode``
6 unmodified lines
161 :meth:`fileno` raises :exc:`io.UnsupportedOperation`, matching the162 pre-``8.3.3`` behavior.163 """164165 _name: str166 _mode: str167 _original_fd: int168169 def __init__(170 self,171 buffer: t.BinaryIO,172 name: str,
2 unmodified lines
175 ) -> None:176 super().__init__(buffer, **kwargs)177 self._name = name178 self._mode = mode160 self._original_fd: int = -1179 self._original_fd = -1180181 def close(self) -> None:182 """The buffer this object contains belongs to some other object,183 so prevent the default ``__del__`` implementation from closing
62 unmodified lines
246 .. versionadded:: 8.0247 Added ``return_value``.248 """249250 runner: CliRunner251 stdout_bytes: bytes252 stderr_bytes: bytes253 output_bytes: bytes254 return_value: t.Any255 exit_code: int256 exception: BaseException | None257 exc_info: ExceptionInfo | None258259 def __init__(260 self,261 runner: CliRunner,262 stdout_bytes: bytes,
1 unmodified line
264 output_bytes: bytes,265 return_value: t.Any,266 exit_code: int,267 exception: BaseException | None,240 exc_info: tuple[type[BaseException], BaseException, TracebackType]241 | None = None,242 ):268 exc_info: ExceptionInfo | None = None,269 ) -> None:270 self.runner = runner271 self.stdout_bytes = stdout_bytes272 self.stderr_bytes = stderr_bytes273 self.output_bytes = output_bytes
73 unmodified lines
347 .. versionchanged:: 8.2348 ``mix_stderr`` parameter has been removed.349 """350351 charset: str352 env: cabc.Mapping[str, str | None]353 echo_stdin: bool354 catch_exceptions: bool355 capture: CaptureMode356357 def __init__(358 self,359 charset: str = "utf-8",360 env: cabc.Mapping[str, str | None] | None = None,
9 unmodified lines
370 raise ValueError(371 f"capture={capture!r} is not supported on Windows. Use 'sys'."372 )373 self.charset = charset341 self.env: cabc.Mapping[str, str | None] = env or {}374 self.env = env or {}375 self.echo_stdin = echo_stdin376 self.catch_exceptions = catch_exceptions344 self.capture: CaptureMode = capture377 self.capture = capture378379 def get_default_prog_name(self, cli: Command) -> str:380 """Given a command object it will return the default program name381 for it. The default is the `name` attribute or ``"root"`` if not
15 unmodified lines
397 self,398 input: str | bytes | t.IO[t.Any] | None = None,399 env: cabc.Mapping[str, str | None] | None = None,400 color: bool = False,368 ) -> cabc.Iterator[tuple[io.BytesIO, io.BytesIO, io.BytesIO]]:401 ) -> cabc.Generator[tuple[io.BytesIO, io.BytesIO, io.BytesIO]]:402 """A context manager that sets up the isolation for invoking of a403 command line tool. This sets up `<stdin>` with the given input data404 and `os.environ` with the overrides from the given dictionary.405 This also rebinds some internals in Click to be mocked (like the
331 unmodified lines
737738 @contextlib.contextmanager739 def isolated_filesystem(740 self, temp_dir: str | os.PathLike[str] | None = None708 ) -> cabc.Iterator[str]:741 ) -> cabc.Generator[str]:742 """A context manager that creates a temporary directory and743 changes the current working directory to it. This isolates tests744 that affect the contents of the CWD to prevent them from745 interfering with each other.
24 unmodified lines