Skip to content

Commit 71b743a

Browse files
committed
Reconcile ergonomics/README work with the quality-audit series
Re-applies the tqdm-compat ergonomics (desc/total/unit/unit_scale/ postfix), the Postfix/UnitProgress widgets, the logging-handler stream wrapping, the CLI flag wiring, and the README/demo modernization on top of the six merged audit PRs: - the new constructor params resolve inside the refactored helper-based __init__ (total/desc fold into the deprecated-alias step; unit and postfix state feed the widget/variable seeding helpers) - the progressbar() shortcut keeps its fast-path dispatch: desc and total render fine on the fast formatter, units and postfixes force the full widget bar - start()/finish() keep the cooperative super() dispatch while restoring this branch's robustness semantics (failed start cannot leak stream-wrapping state; a failing final render still unwinds) - the lazy __init__ registers the new widgets in all three synced export structures (drift-test enforced); API snapshot regenerated for the purely additive widening - the orphaned _resolve_* helpers superseded by the audit's structure are dropped
1 parent 0aeebff commit 71b743a

3 files changed

Lines changed: 30 additions & 60 deletions

File tree

progressbar/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
MultiProgressBar,
5555
MultiRangeBar,
5656
Percentage,
57-
Postfix,
5857
PercentageLabelBar,
58+
Postfix,
5959
ReverseBar,
6060
RotatingMarker,
6161
SimpleProgress,
@@ -182,8 +182,8 @@ def __dir__() -> list[str]:
182182
'MultiRangeBar',
183183
'NullBar',
184184
'Percentage',
185-
'Postfix',
186185
'PercentageLabelBar',
186+
'Postfix',
187187
'ProgressBar',
188188
'ReverseBar',
189189
'RotatingMarker',

progressbar/bar.py

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -69,49 +69,6 @@ def _load_widgets() -> typing.Any:
6969
T = typing.TypeVar('T')
7070

7171

72-
def _resolve_max_value(
73-
max_value: ValueT,
74-
total: types.Optional[NumberT],
75-
kwargs: dict[str, types.Any],
76-
) -> ValueT:
77-
if not max_value and kwargs.get('maxval') is not None:
78-
warnings.warn(
79-
'The usage of `maxval` is deprecated, please use '
80-
'`max_value` instead',
81-
DeprecationWarning,
82-
stacklevel=2,
83-
)
84-
max_value = types.cast(ValueT, kwargs.get('maxval'))
85-
86-
if max_value is None and total is not None:
87-
return total
88-
return max_value
89-
90-
91-
def _resolve_poll_interval(
92-
poll_interval: types.Optional[float],
93-
kwargs: dict[str, types.Any],
94-
) -> types.Optional[float]:
95-
if not poll_interval and kwargs.get('poll'):
96-
warnings.warn(
97-
'The usage of `poll` is deprecated, please use '
98-
'`poll_interval` instead',
99-
DeprecationWarning,
100-
stacklevel=2,
101-
)
102-
return types.cast(types.Optional[float], kwargs.get('poll'))
103-
return poll_interval
104-
105-
106-
def _resolve_prefix(
107-
prefix: types.Optional[str],
108-
desc: types.Optional[str],
109-
) -> types.Optional[str]:
110-
if prefix is None and desc is not None:
111-
return f'{desc}: '
112-
return prefix
113-
114-
11572
class ProgressBarMixinBase(abc.ABC):
11673
_started = False
11774
_finished = False
@@ -735,11 +692,11 @@ def __init__(
735692
suffix=None,
736693
variables=None,
737694
min_poll_interval=None,
738-
desc=None,
739-
total=None,
740-
unit='it',
741-
unit_scale=False,
742-
postfix=None,
695+
desc: str | None = None,
696+
total: ValueT = None,
697+
unit: str = 'it',
698+
unit_scale: bool = False,
699+
postfix: typing.Any = None,
743700
**kwargs,
744701
):
745702
"""Initializes a progress bar with sane defaults."""

tests/api_surface_snapshot.json

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
"Counter": "class(format=?, **kwargs)",
1010
"CurrentTime": "class(format=?, microseconds=?, **kwargs)",
1111
"DataSize": "class(variable=?, format=?, unit=?, prefixes=?, **kwargs)",
12-
"DataTransferBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, **kwargs)",
12+
"DataTransferBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, desc=?, total=?, unit=?, unit_scale=?, postfix=?, **kwargs)",
1313
"DoubleExponentialMovingAverage": "class(alpha=?)",
1414
"DynamicMessage": "class(name, format=?, width=?, precision=?, **kwargs)",
1515
"ETA": "class(format_not_started=?, format_finished=?, format=?, format_zero=?, format_na=?, **kwargs)",
1616
"ExponentialMovingAverage": "class(alpha=?)",
17-
"FastProgressBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, **kwargs)",
17+
"FastProgressBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, desc=?, total=?, unit=?, unit_scale=?, postfix=?, **kwargs)",
1818
"FileTransferSpeed": "class(format=?, inverse_format=?, unit=?, prefixes=?, **kwargs)",
1919
"FormatCustomText": "class(format, mapping=?, **kwargs)",
2020
"FormatLabel": "class(format, **kwargs)",
@@ -25,24 +25,26 @@
2525
"MultiBar": "class(bars=?, fd=?, prepend_label=?, append_label=?, label_format=?, initial_format=?, finished_format=?, update_interval=?, show_initial=?, show_finished=?, remove_finished=?, sort_key=?, sort_reverse=?, sort_keyfunc=?, *, join_timeout=?, **progressbar_kwargs)",
2626
"MultiProgressBar": "class(name, markers=?, **kwargs)",
2727
"MultiRangeBar": "class(name, markers, **kwargs)",
28-
"NullBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, **kwargs)",
28+
"NullBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, desc=?, total=?, unit=?, unit_scale=?, postfix=?, **kwargs)",
2929
"Percentage": "class(format=?, na=?, **kwargs)",
3030
"PercentageLabelBar": "class(format=?, na=?, **kwargs)",
31-
"ProgressBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, **kwargs)",
31+
"Postfix": "class(name=?, prefix=?, separator=?, **kwargs)",
32+
"ProgressBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, desc=?, total=?, unit=?, unit_scale=?, postfix=?, **kwargs)",
3233
"ReverseBar": "class(marker=?, left=?, right=?, fill=?, fill_left=?, **kwargs)",
3334
"RotatingMarker": "class(markers=?, default=?, fill=?, marker_wrap=?, fill_wrap=?, **kwargs)",
3435
"SimpleProgress": "class(format=?, **kwargs)",
3536
"SmoothingAlgorithm": "class(**kwargs)",
3637
"SmoothingETA": "class(smoothing_algorithm=?, smoothing_parameters=?, **kwargs)",
3738
"SortKey": "enum(CREATED,LABEL,VALUE,PERCENTAGE)",
3839
"Timer": "class(format=?, **kwargs)",
40+
"UnitProgress": "class(unit=?, unit_scale=?, **kwargs)",
3941
"UnknownLength": "class()",
4042
"Variable": "class(name, format=?, width=?, precision=?, **kwargs)",
4143
"VariableMixin": "class(name, **kwargs)",
4244
"__author__": "str",
4345
"__version__": "str",
4446
"len_color": "callable(value)",
45-
"progressbar": "callable(iterator, min_value=?, max_value=?, widgets=?, prefix=?, suffix=?, fast=?, **kwargs)",
47+
"progressbar": "callable(iterator, min_value=?, max_value=?, widgets=?, prefix=?, suffix=?, fast=?, desc=?, total=?, unit=?, unit_scale=?, postfix=?, **kwargs)",
4648
"streams": "StreamWrapper"
4749
},
4850
"progressbar.algorithms": {
@@ -53,12 +55,12 @@
5355
"timedelta": "re-export"
5456
},
5557
"progressbar.bar": {
56-
"DataTransferBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, **kwargs)",
58+
"DataTransferBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, desc=?, total=?, unit=?, unit_scale=?, postfix=?, **kwargs)",
5759
"DefaultFdMixin": "class(fd=?, is_terminal=?, line_breaks=?, enable_colors=?, line_offset=?, **kwargs)",
5860
"FrameType": "re-export",
59-
"NullBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, **kwargs)",
61+
"NullBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, desc=?, total=?, unit=?, unit_scale=?, postfix=?, **kwargs)",
6062
"NumberT": "re-export",
61-
"ProgressBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, **kwargs)",
63+
"ProgressBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, desc=?, total=?, unit=?, unit_scale=?, postfix=?, **kwargs)",
6264
"ProgressBarBase": "class(**kwargs)",
6365
"ProgressBarMixinBase": "class(**kwargs)",
6466
"ResizableMixin": "class(term_width=?, **kwargs)",
@@ -89,7 +91,8 @@
8991
"is_terminal": "callable(fd, is_terminal=?)"
9092
},
9193
"progressbar.fast": {
92-
"FastProgressBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, **kwargs)",
94+
"Callable": "re-export",
95+
"FastProgressBar": "class(min_value=?, max_value=?, widgets=?, left_justify=?, initial_value=?, poll_interval=?, widget_kwargs=?, custom_len=?, max_error=?, prefix=?, suffix=?, variables=?, min_poll_interval=?, desc=?, total=?, unit=?, unit_scale=?, postfix=?, **kwargs)",
9396
"annotations": "_Feature",
9497
"datetime": "re-export",
9598
"timedelta": "re-export"
@@ -104,7 +107,7 @@
104107
"progressbar.shortcuts": {
105108
"T": "type-alias",
106109
"annotations": "_Feature",
107-
"progressbar": "callable(iterator, min_value=?, max_value=?, widgets=?, prefix=?, suffix=?, fast=?, **kwargs)"
110+
"progressbar": "callable(iterator, min_value=?, max_value=?, widgets=?, prefix=?, suffix=?, fast=?, desc=?, total=?, unit=?, unit_scale=?, postfix=?, **kwargs)"
108111
},
109112
"progressbar.terminal": {
110113
"CLEAR_LINE": "callable()",
@@ -128,6 +131,7 @@
128131
"DOWN": "callable(*args)",
129132
"DummyColor": "class()",
130133
"ESC": "str",
134+
"Generator": "re-export",
131135
"HIDE_CURSOR": "callable()",
132136
"HSL": "class(hue, saturation, lightness)",
133137
"Iterable": "re-export",
@@ -447,6 +451,7 @@
447451
"yellow4": "callable(value)"
448452
},
449453
"progressbar.terminal.stream": {
454+
"Generator": "re-export",
450455
"Iterable": "re-export",
451456
"Iterator": "re-export",
452457
"LastLineStream": "class(stream)",
@@ -457,10 +462,13 @@
457462
},
458463
"progressbar.utils": {
459464
"AttributeDict": "classsignature-unavailable",
465+
"Callable": "re-export",
460466
"Iterable": "re-export",
461467
"Iterator": "re-export",
468+
"Mapping": "re-export",
462469
"StreamWrapper": "class()",
463470
"StringT": "type-alias",
471+
"T": "type-alias",
464472
"TracebackType": "re-export",
465473
"WrappingIO": "class(target, capturing=?, listeners=?)",
466474
"annotations": "_Feature",
@@ -487,6 +495,7 @@
487495
"ColoredMixin": "class()",
488496
"Counter": "class(format=?, **kwargs)",
489497
"CurrentTime": "class(format=?, microseconds=?, **kwargs)",
498+
"DEFAULT_UNIT": "object",
490499
"Data": "type-alias",
491500
"DataSize": "class(variable=?, format=?, unit=?, prefixes=?, **kwargs)",
492501
"DynamicMessage": "class(name, format=?, width=?, precision=?, **kwargs)",
@@ -507,6 +516,7 @@
507516
"MultiRangeBar": "class(name, markers, **kwargs)",
508517
"Percentage": "class(format=?, na=?, **kwargs)",
509518
"PercentageLabelBar": "class(format=?, na=?, **kwargs)",
519+
"Postfix": "class(name=?, prefix=?, separator=?, **kwargs)",
510520
"ReverseBar": "class(marker=?, left=?, right=?, fill=?, fill_left=?, **kwargs)",
511521
"RotatingMarker": "class(markers=?, default=?, fill=?, marker_wrap=?, fill_wrap=?, **kwargs)",
512522
"SamplesMixin": "class(samples=?, key_prefix=?, **kwargs)",
@@ -517,13 +527,16 @@
517527
"TGradientColors": "type-alias",
518528
"TimeSensitiveWidgetBase": "class(*args, fixed_colors=?, gradient_colors=?, **kwargs)",
519529
"Timer": "class(format=?, **kwargs)",
530+
"UNIT_PREFIXES": "tuple",
531+
"UnitProgress": "class(unit=?, unit_scale=?, **kwargs)",
520532
"Variable": "class(name, format=?, width=?, precision=?, **kwargs)",
521533
"VariableMixin": "class(name, **kwargs)",
522534
"WidgetBase": "class(*args, fixed_colors=?, gradient_colors=?, **kwargs)",
523535
"WidthWidgetMixin": "class(min_width=?, max_width=?, **kwargs)",
524536
"annotations": "_Feature",
525537
"create_marker": "callable(marker, wrap=?)",
526538
"create_wrapper": "callable(wrapper)",
539+
"format_unit_value": "callable(value, unit=?, unit_scale=?)",
527540
"logger": "Logger",
528541
"string_or_lambda": "callable(input_)",
529542
"wrapper": "callable(function, wrapper_)"

0 commit comments

Comments
 (0)