ProgressBar inherits Generic
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent c49a72f · 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
Provenance
- Commit
0dcfc32- Tree
bccf1c2- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
c49a72f
3 files changed+7 added−5 removed
modified:src/click/_termui_impl.py+4 added-4 removed
30 unmodified lines31 BEFORE_BAR = "\r\033[?25l"32 AFTER_BAR = "\033[?25h\n"33 34 35-class ProgressBar:35+class ProgressBar(t.Generic[V]):36 def __init__(37 self,38 iterable: t.Optional[t.Iterable[V]],39 length: t.Optional[int] = None,9 unmodified lines49 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_sep42 unmodified lines100 101 def __exit__(self, exc_type, exc_value, tb): # type: ignore102 self.render_finish()103 104- 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 lines112 # 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))117 118 def render_finish(self) -> None:119 if self.is_hidden:120 return597 unmodified linesmodified:src/click/termui.py+1 added-1 removed
316 unmodified lines317 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 rendered482 unmodified linesmodified:CHANGES.rst+2 added
8 unmodified lines9 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`15 16 17 Version 8.0.018 -------------854 unmodified lines