Add type annotations for instance attributes in `testing`
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·+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
Provenance
- Commit
e39679a- Tree
b5f6e02- Author
jorenham <jhammudoglu@gmail.com>- Committer
jorenham <jhammudoglu@gmail.com>- Parent
648d7c4
1 file changed+48 added−15 removed
modified:src/click/testing.py+48 added-15 removed
20 unmodified lines21 from _typeshed import ReadableBuffer22 23 from .core import Command24 25-CaptureMode = t.Literal["sys", "fd"]25+CaptureMode: t.TypeAlias = t.Literal["sys", "fd"]26+ExceptionInfo: t.TypeAlias = tuple[type[BaseException], BaseException, TracebackType]27 28 29 class EchoingStdin:30+ _input: t.BinaryIO31+ _output: t.BinaryIO32+ _paused: bool33+34 def __init__(self, input: t.BinaryIO, output: t.BinaryIO) -> None:35 self._input = input36 self._output = output37 self._paused = False26 unmodified lines64 return repr(self._input)65 66 67 @contextlib.contextmanager63-def _pause_echo(stream: EchoingStdin | None) -> cabc.Iterator[None]:68+def _pause_echo(stream: EchoingStdin | None) -> cabc.Generator[None]:69 if stream is None:70 yield71 else:72 stream._paused = True11 unmodified lines84 85 .. versionadded:: 8.4.086 """87 88+ _targetfd: int89+ saved_fd: int90+ _tmpfile: t.BinaryIO | None91+92 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 = None96 97 def start(self) -> None:98 self.saved_fd = os.dup(self._targetfd)99 self._tmpfile = tempfile.TemporaryFile(buffering=0)16 unmodified lines116 117 .. versionadded:: 8.2118 """119 120+ copy_to: io.BytesIO121+122 def __init__(self, copy_to: io.BytesIO) -> None:123 super().__init__()124 self.copy_to = copy_to125 13 unmodified lines139 140 .. versionadded:: 8.2141 """142 143+ output: io.BytesIO144+ stdout: BytesIOCopy145+ stderr: BytesIOCopy146+147 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)151 152 153 class _NamedTextIOWrapper(io.TextIOWrapper):154 """A :class:`~io.TextIOWrapper` with custom ``name`` and ``mode``6 unmodified lines161 :meth:`fileno` raises :exc:`io.UnsupportedOperation`, matching the162 pre-``8.3.3`` behavior.163 """164 165+ _name: str166+ _mode: str167+ _original_fd: int168+169 def __init__(170 self,171 buffer: t.BinaryIO,172 name: str,2 unmodified lines175 ) -> None:176 super().__init__(buffer, **kwargs)177 self._name = name178 self._mode = mode160- self._original_fd: int = -1179+ self._original_fd = -1180 181 def close(self) -> None:182 """The buffer this object contains belongs to some other object,183 so prevent the default ``__del__`` implementation from closing62 unmodified lines246 .. versionadded:: 8.0247 Added ``return_value``.248 """249 250+ runner: CliRunner251+ stdout_bytes: bytes252+ stderr_bytes: bytes253+ output_bytes: bytes254+ return_value: t.Any255+ exit_code: int256+ exception: BaseException | None257+ exc_info: ExceptionInfo | None258+259 def __init__(260 self,261 runner: CliRunner,262 stdout_bytes: bytes,1 unmodified line264 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_bytes73 unmodified lines347 .. versionchanged:: 8.2348 ``mix_stderr`` parameter has been removed.349 """350 351+ charset: str352+ env: cabc.Mapping[str, str | None]353+ echo_stdin: bool354+ catch_exceptions: bool355+ capture: CaptureMode356+357 def __init__(358 self,359 charset: str = "utf-8",360 env: cabc.Mapping[str, str | None] | None = None,9 unmodified lines370 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 = capture378 379 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 not15 unmodified lines397 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 the331 unmodified lines737 738 @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