Skip to content
Myr

specialize progressbar(length=...) as ProgressBar[int] (#2630)

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

authored by Anthony Sottile · committed by GitHub · parent 0d69b6c · Browse files · 3 files+67 added−0 removed
This commit

State

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

Trailers

  • Co-authored-by: Andreas Backx <andreas@backx.org>

Diff stats

3 files+67 added−0 removed

  • tests:+24 added−0 removed
  • other:+43 added−0 removed

3 files+67 added−0 removed

modified:src/click/termui.py+41 added
282 unmodified lines
283284 return pager(itertools.chain(text_generator, "\n"), color)285286287@t.overload288def progressbar(289 *,290 length: int,291 label: str | None = None,292 hidden: bool = False,293 show_eta: bool = True,294 show_percent: bool | None = None,295 show_pos: bool = False,296 fill_char: str = "#",297 empty_char: str = "-",298 bar_template: str = "%(label)s [%(bar)s] %(info)s",299 info_sep: str = " ",300 width: int = 36,301 file: t.TextIO | None = None,302 color: bool | None = None,303 update_min_steps: int = 1,304) -> ProgressBar[int]: ...305306307@t.overload308def progressbar(309 iterable: cabc.Iterable[V] | None = None,310 length: int | None = None,311 label: str | None = None,312 hidden: bool = False,
8 unmodified lines
321 width: int = 36,322 file: t.TextIO | None = None,323 color: bool | None = None,324 update_min_steps: int = 1,325) -> ProgressBar[V]: ...326327328def progressbar(329 iterable: cabc.Iterable[V] | None = None,330 length: int | None = None,331 label: str | None = None,332 hidden: bool = False,333 show_eta: bool = True,334 show_percent: bool | None = None,335 show_pos: bool = False,336 item_show_func: t.Callable[[V | None], str | None] | None = None,337 fill_char: str = "#",338 empty_char: str = "-",339 bar_template: str = "%(label)s [%(bar)s] %(info)s",340 info_sep: str = " ",341 width: int = 36,342 file: t.TextIO | None = None,343 color: bool | None = None,344 update_min_steps: int = 1,345) -> ProgressBar[V]:346 """This function creates an iterable context manager that can be used347 to iterate over something while showing a progress bar. It will348 either iterate over the `iterable` or `length` items (that are counted
519 unmodified lines
added:tests/typing/typing_progressbar.py+24 added
1from __future__ import annotations23from typing_extensions import assert_type45from click import progressbar6from click._termui_impl import ProgressBar789def test_length_is_int() -> None:10 with progressbar(length=5) as bar:11 assert_type(bar, ProgressBar[int])12 for i in bar:13 assert_type(i, int)141516def it() -> tuple[str, ...]:17 return ("hello", "world")181920def test_generic_on_iterable() -> None:21 with progressbar(it()) as bar:22 assert_type(bar, ProgressBar[str])23 for s in bar:24 assert_type(s, str)
modified:CHANGES.rst+2 added
64 unmodified lines
65- ``click.edit(filename)`` now supports passing an iterable of filenames in66 case the editor supports editing multiple files at once. Its return type67 is now also typed: ``AnyStr`` if ``text`` is passed, otherwise ``None``.68 :issue:`2067` :pr:`2068`69- Specialized typing of ``progressbar(length=...)`` as ``ProgressBar[int]``.70 :pr:`2630`717273Version 8.1.874-------------
1118 unmodified lines