Skip to content

Commit 4957df1

Browse files
committed
remove usage of cabc in _click classes
1 parent 479199d commit 4957df1

10 files changed

Lines changed: 61 additions & 66 deletions

File tree

typer/_click/_compat.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from __future__ import annotations
22

33
import codecs
4-
import collections.abc as cabc
54
import io
65
import os
76
import re
87
import sys
98
import typing as t
9+
from collections.abc import Mapping, MutableMapping
1010
from types import TracebackType
1111
from weakref import WeakKeyDictionary
1212

@@ -517,7 +517,7 @@ def _get_argv_encoding() -> str:
517517

518518
return locale.getpreferredencoding()
519519

520-
_ansi_stream_wrappers: cabc.MutableMapping[t.TextIO, t.TextIO] = WeakKeyDictionary()
520+
_ansi_stream_wrappers: MutableMapping[t.TextIO, t.TextIO] = WeakKeyDictionary()
521521

522522
def auto_wrap_for_ansi(stream: t.TextIO, color: bool | None = None) -> t.TextIO:
523523
"""Support ANSI color and style codes on Windows by wrapping a
@@ -580,7 +580,7 @@ def _make_cached_stream_func(
580580
src_func: t.Callable[[], t.TextIO | None],
581581
wrapper_func: t.Callable[[], t.TextIO],
582582
) -> t.Callable[[], t.TextIO | None]:
583-
cache: cabc.MutableMapping[t.TextIO, t.TextIO] = WeakKeyDictionary()
583+
cache: MutableMapping[t.TextIO, t.TextIO] = WeakKeyDictionary()
584584

585585
def func() -> t.TextIO | None:
586586
stream = src_func()
@@ -609,13 +609,13 @@ def func() -> t.TextIO | None:
609609
_default_text_stderr = _make_cached_stream_func(lambda: sys.stderr, get_text_stderr)
610610

611611

612-
binary_streams: cabc.Mapping[str, t.Callable[[], t.BinaryIO]] = {
612+
binary_streams: Mapping[str, t.Callable[[], t.BinaryIO]] = {
613613
"stdin": get_binary_stdin,
614614
"stdout": get_binary_stdout,
615615
"stderr": get_binary_stderr,
616616
}
617617

618-
text_streams: cabc.Mapping[str, t.Callable[[str | None, str | None], t.TextIO]] = {
618+
text_streams: Mapping[str, t.Callable[[str | None, str | None], t.TextIO]] = {
619619
"stdin": get_text_stdin,
620620
"stdout": get_text_stdout,
621621
"stderr": get_text_stderr,

typer/_click/_termui_impl.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
from __future__ import annotations
88

9-
import collections.abc as cabc
109
import contextlib
1110
import math
1211
import os
1312
import sys
1413
import time
1514
import typing as t
15+
from collections.abc import Iterable, Iterator
1616
from io import StringIO
1717
from types import TracebackType
1818

@@ -39,7 +39,7 @@
3939
class ProgressBar(t.Generic[V]):
4040
def __init__(
4141
self,
42-
iterable: cabc.Iterable[V] | None,
42+
iterable: Iterable[V] | None,
4343
length: int | None = None,
4444
fill_char: str = "#",
4545
empty_char: str = " ",
@@ -92,8 +92,8 @@ def __init__(
9292
if iterable is None:
9393
if length is None:
9494
raise TypeError("iterable or length is required")
95-
iterable = t.cast("cabc.Iterable[V]", range(length))
96-
self.iter: cabc.Iterable[V] = iter(iterable)
95+
iterable = t.cast("Iterable[V]", range(length))
96+
self.iter: Iterable[V] = iter(iterable)
9797
self.length = length
9898
self.pos: int = 0
9999
self.avg: list[float] = []
@@ -121,7 +121,7 @@ def __exit__(
121121
) -> None:
122122
self.render_finish()
123123

124-
def __iter__(self) -> cabc.Iterator[V]:
124+
def __iter__(self) -> Iterator[V]:
125125
if not self.entered:
126126
raise RuntimeError("You need to use progress bars in a with block.")
127127
self.render_progress()
@@ -328,7 +328,7 @@ def finish(self) -> None:
328328
self.current_item = None
329329
self.finished = True
330330

331-
def generator(self) -> cabc.Iterator[V]:
331+
def generator(self) -> Iterator[V]:
332332
"""Return a generator which yields the items added to the bar
333333
during construction, and updates the progress bar *after* the
334334
yielded block returns.
@@ -450,7 +450,7 @@ def _translate_ch_to_exc(ch: str) -> None:
450450
import msvcrt
451451

452452
@contextlib.contextmanager
453-
def raw_terminal() -> cabc.Iterator[int]:
453+
def raw_terminal() -> Iterator[int]:
454454
yield -1
455455

456456
def getchar(echo: bool) -> str:
@@ -504,7 +504,7 @@ def getchar(echo: bool) -> str:
504504
import tty
505505

506506
@contextlib.contextmanager
507-
def raw_terminal() -> cabc.Iterator[int]:
507+
def raw_terminal() -> Iterator[int]:
508508
f: t.TextIO | None
509509
fd: int
510510

typer/_click/_textwrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

3-
import collections.abc as cabc
43
import textwrap
4+
from collections.abc import Iterator
55
from contextlib import contextmanager
66

77

@@ -25,7 +25,7 @@ def _handle_long_word(
2525
cur_line.append(reversed_chunks.pop())
2626

2727
@contextmanager
28-
def extra_indent(self, indent: str) -> cabc.Iterator[None]:
28+
def extra_indent(self, indent: str) -> Iterator[None]:
2929
old_initial_indent = self.initial_indent
3030
old_subsequent_indent = self.subsequent_indent
3131
self.initial_indent += indent

typer/_click/_winconsole.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# echo and prompt.
99
from __future__ import annotations
1010

11-
import collections.abc as cabc
1211
import io
1312
import sys
1413
import time
@@ -207,7 +206,7 @@ def write(self, x: t.AnyStr) -> int:
207206
pass
208207
return self.buffer.write(x)
209208

210-
def writelines(self, lines: cabc.Iterable[t.AnyStr]) -> None:
209+
def writelines(self, lines: t.Iterable[t.AnyStr]) -> None:
211210
for line in lines:
212211
self.write(line)
213212

@@ -251,7 +250,7 @@ def _get_text_stderr(buffer_stream: t.BinaryIO) -> t.TextIO:
251250
return t.cast(t.TextIO, ConsoleStream(text_stream, buffer_stream))
252251

253252

254-
_stream_factories: cabc.Mapping[int, t.Callable[[t.BinaryIO], t.TextIO]] = {
253+
_stream_factories: t.Mapping[int, t.Callable[[t.BinaryIO], t.TextIO]] = {
255254
0: _get_text_stdin,
256255
1: _get_text_stdout,
257256
2: _get_text_stderr,

typer/_click/core.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import collections.abc as cabc
21
import enum
32
import inspect
43
import os
54
from abc import ABC, abstractmethod
6-
from collections.abc import Callable
5+
from collections.abc import Callable, Iterator, Mapping, MutableMapping, Sequence
76
from contextlib import AbstractContextManager, ExitStack, contextmanager
87
from types import TracebackType
98
from typing import (
@@ -45,7 +44,7 @@
4544

4645
def _complete_visible_commands(
4746
ctx: "Context", incomplete: str
48-
) -> cabc.Iterator[tuple[str, "Command"]]:
47+
) -> Iterator[tuple[str, "Command"]]:
4948
"""List all the subcommands of a group that start with the
5049
incomplete value and aren't hidden.
5150
"""
@@ -65,7 +64,7 @@ def _complete_visible_commands(
6564
@contextmanager
6665
def augment_usage_errors(
6766
ctx: "Context", param: Union["Parameter", None] = None
68-
) -> cabc.Iterator[None]:
67+
) -> Iterator[None]:
6968
"""Context manager that attaches extra information to exceptions."""
7069
try:
7170
yield
@@ -82,8 +81,8 @@ def augment_usage_errors(
8281

8382

8483
def iter_params_for_processing(
85-
invocation_order: cabc.Sequence["Parameter"],
86-
declaration_order: cabc.Sequence["Parameter"],
84+
invocation_order: Sequence["Parameter"],
85+
declaration_order: Sequence["Parameter"],
8786
) -> list["Parameter"]:
8887
"""Returns all declared parameters in the order they should be processed.
8988
@@ -147,7 +146,7 @@ def __init__(
147146
info_name: str | None = None,
148147
obj: Any | None = None,
149148
auto_envvar_prefix: str | None = None,
150-
default_map: cabc.MutableMapping[str, Any] | None = None,
149+
default_map: MutableMapping[str, Any] | None = None,
151150
terminal_width: int | None = None,
152151
max_content_width: int | None = None,
153152
resilient_parsing: bool = False,
@@ -186,7 +185,7 @@ def __init__(
186185
):
187186
default_map = parent.default_map.get(info_name)
188187

189-
self.default_map: cabc.MutableMapping[str, Any] | None = default_map
188+
self.default_map: MutableMapping[str, Any] | None = default_map
190189

191190
# This flag indicates if a subcommand is going to be executed.
192191
self.invoked_subcommand: str | None = None
@@ -291,7 +290,7 @@ def __exit__(
291290
return exit_result
292291

293292
@contextmanager
294-
def scope(self, cleanup: bool = True) -> cabc.Iterator["Context"]:
293+
def scope(self, cleanup: bool = True) -> Iterator["Context"]:
295294
"""This helper method can be used with the context object to promote
296295
it to the current thread local (see `get_current_context`).
297296
The default behavior of this is to invoke the cleanup functions which
@@ -524,7 +523,7 @@ class Command(ABC):
524523
def __init__(
525524
self,
526525
name: str | None,
527-
context_settings: cabc.MutableMapping[str, Any] | None = None,
526+
context_settings: MutableMapping[str, Any] | None = None,
528527
callback: Callable[..., Any] | None = None,
529528
params: list["Parameter"] | None = None,
530529
help: str | None = None,
@@ -541,7 +540,7 @@ def __init__(
541540
if context_settings is None:
542541
context_settings = {}
543542

544-
self.context_settings: cabc.MutableMapping[str, Any] = context_settings
543+
self.context_settings: MutableMapping[str, Any] = context_settings
545544

546545
self.callback = callback
547546
self.params: list[Parameter] = params or []
@@ -788,7 +787,7 @@ def shell_complete(self, ctx: Context, incomplete: str) -> list["CompletionItem"
788787
@abstractmethod
789788
def main(
790789
self,
791-
args: cabc.Sequence[str] | None = None,
790+
args: Sequence[str] | None = None,
792791
prog_name: str | None = None,
793792
complete_var: str | None = None,
794793
standalone_mode: bool = True,
@@ -800,7 +799,7 @@ def main(
800799
@abstractmethod
801800
def _main_shell_completion(
802801
self,
803-
ctx_args: cabc.MutableMapping[str, Any],
802+
ctx_args: MutableMapping[str, Any],
804803
prog_name: str,
805804
complete_var: str | None = None,
806805
) -> None:
@@ -824,7 +823,7 @@ class Parameter(ABC):
824823

825824
def __init__(
826825
self,
827-
param_decls: cabc.Sequence[str] | None = None,
826+
param_decls: Sequence[str] | None = None,
828827
type: types.ParamType | Any | None = None,
829828
required: bool = False,
830829
default: Any | Callable[[], Any] | None = None,
@@ -834,7 +833,7 @@ def __init__(
834833
metavar: str | None = None,
835834
expose_value: bool = True,
836835
is_eager: bool = False,
837-
envvar: str | cabc.Sequence[str] | None = None,
836+
envvar: str | Sequence[str] | None = None,
838837
shell_complete: Callable[
839838
[Context, "Parameter", str], list["CompletionItem"] | list[str]
840839
]
@@ -872,7 +871,7 @@ def __repr__(self) -> str:
872871

873872
@abstractmethod
874873
def _parse_decls(
875-
self, decls: cabc.Sequence[str], expose_value: bool
874+
self, decls: Sequence[str], expose_value: bool
876875
) -> tuple[str | None, list[str], list[str]]:
877876
pass # pragma: no cover
878877

@@ -924,7 +923,7 @@ def add_to_parser(self, parser: _OptionParser, ctx: Context) -> None:
924923
pass # pragma: no cover
925924

926925
def consume_value(
927-
self, ctx: Context, opts: cabc.Mapping[str, Any]
926+
self, ctx: Context, opts: Mapping[str, Any]
928927
) -> tuple[Any, ParameterSource]:
929928
value = opts.get(self.name) # type: ignore
930929
source = ParameterSource.COMMANDLINE
@@ -950,7 +949,7 @@ def type_cast_value(self, ctx: Context, value: Any) -> Any:
950949
if value is None:
951950
return () if self.multiple or self.nargs == -1 else None
952951

953-
def check_iter(value: Any) -> cabc.Iterator[Any]:
952+
def check_iter(value: Any) -> Iterator[Any]:
954953
assert not isinstance(value, str)
955954
return iter(value)
956955

@@ -1037,7 +1036,7 @@ def resolve_envvar_value(self, ctx: Context) -> str | None:
10371036

10381037
return None
10391038

1040-
def value_from_envvar(self, ctx: Context) -> str | cabc.Sequence[str] | None:
1039+
def value_from_envvar(self, ctx: Context) -> str | Sequence[str] | None:
10411040
"""Process the raw environment variable string for this parameter.
10421041
10431042
Returns the string as-is or splits it into a sequence of strings if the
@@ -1052,7 +1051,7 @@ def value_from_envvar(self, ctx: Context) -> str | cabc.Sequence[str] | None:
10521051
return rv
10531052

10541053
def handle_parse_result(
1055-
self, ctx: Context, opts: cabc.Mapping[str, Any], args: list[str]
1054+
self, ctx: Context, opts: Mapping[str, Any], args: list[str]
10561055
) -> tuple[Any, list[str]]:
10571056
"""Process the value produced by the parser from user input.
10581057

typer/_click/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .core import Command, Context, Parameter
1414

1515

16-
def _join_param_hints(param_hint: cabc.Sequence[str] | str | None) -> str | None:
16+
def _join_param_hints(param_hint: t.Sequence[str] | str | None) -> str | None:
1717
if param_hint is not None and not isinstance(param_hint, str):
1818
return " / ".join(repr(x) for x in param_hint)
1919

typer/_click/termui.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import collections.abc as cabc
21
import io
3-
from collections.abc import Callable
2+
from collections.abc import Callable, Iterable
43
from contextlib import AbstractContextManager
54
from typing import IO, TYPE_CHECKING, Any, AnyStr, TextIO, TypeVar, overload
65

@@ -216,7 +215,7 @@ def progressbar(
216215

217216
@overload
218217
def progressbar(
219-
iterable: cabc.Iterable[V] | None = None,
218+
iterable: Iterable[V] | None = None,
220219
length: int | None = None,
221220
label: str | None = None,
222221
hidden: bool = False,
@@ -236,7 +235,7 @@ def progressbar(
236235

237236

238237
def progressbar(
239-
iterable: cabc.Iterable[V] | None = None,
238+
iterable: Iterable[V] | None = None,
240239
length: int | None = None,
241240
label: str | None = None,
242241
hidden: bool = False,

0 commit comments

Comments
 (0)