Skip to content
Myr

Merge pull request #1909 from pallets/progressbar-typing

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

ProgressBar inherits Generic

authored by David Lord · committed by GitHub · parents c49a72f, 0dcfc32 · Browse files · 3 files+7 added−5 removed
This commit

State

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

Diff stats

3 files+7 added−5 removed

  • other:+7 added−5 removed

3 files+7 added−5 removed

modified:src/click/_termui_impl.py+4 added-4 removed
30 unmodified lines
31 BEFORE_BAR = "\r\033[?25l"32 AFTER_BAR = "\033[?25h\n"333435class ProgressBar:35class ProgressBar(t.Generic[V]):36 def __init__(37 self,38 iterable: t.Optional[t.Iterable[V]],39 length: t.Optional[int] = None,
9 unmodified lines
49 file: t.Optional[t.TextIO] = None,50 color: t.Optional[bool] = None,51 update_min_steps: int = 1,52 width: int = 30,53 ):53 ) -> None:54 self.fill_char = fill_char55 self.empty_char = empty_char56 self.bar_template = bar_template57 self.info_sep = info_sep
42 unmodified lines
100101 def __exit__(self, exc_type, exc_value, tb): # type: ignore102 self.render_finish()103104 def __iter__(self) -> t.Iterable[V]:104 def __iter__(self) -> t.Iterator[V]:105 if not self.entered:106 raise RuntimeError("You need to use progress bars in a with block.")107 self.render_progress()108 return self.generator()
3 unmodified lines
112 # returned by iter(self); use that to define next(). This works113 # because `self.iter` is an iterable consumed by that generator,114 # so it is re-entry safe. Calling `next(self.generator())`115 # twice works and does "what you want".116 return next(iter(self)) # type: ignore116 return next(iter(self))117118 def render_finish(self) -> None:119 if self.is_hidden:120 return
597 unmodified lines
modified:src/click/termui.py+1 added-1 removed
316 unmodified lines
317 width: int = 36,318 file: t.Optional[t.TextIO] = None,319 color: t.Optional[bool] = None,320 update_min_steps: int = 1,321) -> "ProgressBar":321) -> "ProgressBar[V]":322 """This function creates an iterable context manager that can be used323 to iterate over something while showing a progress bar. It will324 either iterate over the `iterable` or `length` items (that are counted325 up). While iteration happens, this function will print a rendered
482 unmodified lines
modified:CHANGES.rst+2 added
8 unmodified lines
9 in user projects. :issue:`1879`10- Annotate ``Context.obj`` as ``Any`` so type checking allows all11 operations on the arbitrary object. :issue:`1885`12- Fix some types that weren't available in Python 3.6.0. :issue:`1882`13- Fix type checking for iterating over ``ProgressBar`` object.14 :issue:`1892`151617Version 8.0.018-------------
854 unmodified lines