MCPcopy
hub / github.com/pallets/click / generator

Method generator

src/click/_termui_impl.py:355–386  ·  view source on GitHub ↗

Return a generator which yields the items added to the bar during construction, and updates the progress bar *after* the yielded block returns.

(self)

Source from the content-addressed store, hash-verified

353 self.finished = True
354
355 def generator(self) -> cabc.Iterator[V]:
356 """Return a generator which yields the items added to the bar
357 during construction, and updates the progress bar *after* the
358 yielded block returns.
359 """
360 # WARNING: the iterator interface for `ProgressBar` relies on
361 # this and only works because this is a simple generator which
362 # doesn't create or manage additional state. If this function
363 # changes, the impact should be evaluated both against
364 # `iter(bar)` and `next(bar)`. `next()` in particular may call
365 # `self.generator()` repeatedly, and this must remain safe in
366 # order for that interface to work.
367 if not self.entered:
368 raise RuntimeError("You need to use progress bars in a with block.")
369
370 if not self._is_atty:
371 yield from self.iter
372 else:
373 for rv in self.iter:
374 self.current_item = rv
375
376 # This allows show_item_func to be updated before the
377 # item is processed. Only trigger at the beginning of
378 # the update interval.
379 if self._completed_intervals == 0:
380 self.render_progress()
381
382 yield rv
383 self.update(1)
384
385 self.finish()
386 self.render_progress()
387
388
389class MaybeStripAnsi(io.TextIOWrapper):

Callers 1

__iter__Method · 0.95

Calls 3

render_progressMethod · 0.95
updateMethod · 0.95
finishMethod · 0.95

Tested by

no test coverage detected