Skip to content

Commit

Permalink
more ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Dec 6, 2024
1 parent 039a239 commit 5488734
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 46 deletions.
11 changes: 6 additions & 5 deletions examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def do_something(bar):
bar_labels = []
for i in range(BARS):
# Get a progressbar
bar_label = 'Bar #%d' % i
bar_label = f'Bar #{i:d}'
bar_labels.append(bar_label)
multibar[bar_label]
assert multibar[bar_label] is not None

for _ in range(N * BARS):
time.sleep(0.005)
Expand Down Expand Up @@ -148,7 +148,7 @@ def with_example_stdout_redirection() -> None:
with progressbar.ProgressBar(max_value=10, redirect_stdout=True) as p:
for i in range(10):
if i % 3 == 0:
print('Some print statement %i' % i)
print(f'Some print statement {i:d}')
# do something
p.update(i)
time.sleep(0.1)
Expand Down Expand Up @@ -544,8 +544,9 @@ def with_right_justify() -> None:

@example
def exceeding_maximum() -> None:
with progressbar.ProgressBar(max_value=1) as progress, contextlib.suppress(
ValueError
with (
progressbar.ProgressBar(max_value=1) as progress,
contextlib.suppress(ValueError),
):
progress.update(2)

Expand Down
62 changes: 31 additions & 31 deletions progressbar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,47 +45,47 @@

__date__ = str(date.today())
__all__ = [
'progressbar',
'len_color',
'streams',
'Timer',
'ETA',
'AdaptiveETA',
'AbsoluteETA',
'SmoothingETA',
'SmoothingAlgorithm',
'ExponentialMovingAverage',
'DoubleExponentialMovingAverage',
'DataSize',
'FileTransferSpeed',
'AdaptiveETA',
'AdaptiveTransferSpeed',
'AnimatedMarker',
'Counter',
'Percentage',
'FormatLabel',
'SimpleProgress',
'Bar',
'ReverseBar',
'BouncingBar',
'UnknownLength',
'ProgressBar',
'Counter',
'CurrentTime',
'DataSize',
'DataTransferBar',
'RotatingMarker',
'VariableMixin',
'MultiRangeBar',
'MultiProgressBar',
'GranularBar',
'FormatLabelBar',
'PercentageLabelBar',
'Variable',
'DoubleExponentialMovingAverage',
'DynamicMessage',
'ExponentialMovingAverage',
'FileTransferSpeed',
'FormatCustomText',
'CurrentTime',
'NullBar',
'__author__',
'__version__',
'FormatLabel',
'FormatLabelBar',
'GranularBar',
'JobStatusBar',
'LineOffsetStreamWrapper',
'MultiBar',
'MultiProgressBar',
'MultiRangeBar',
'NullBar',
'Percentage',
'PercentageLabelBar',
'ProgressBar',
'ReverseBar',
'RotatingMarker',
'SimpleProgress',
'SmoothingAlgorithm',
'SmoothingETA',
'SortKey',
'JobStatusBar',
'Timer',
'UnknownLength',
'Variable',
'VariableMixin',
'__author__',
'__version__',
'len_color',
'progressbar',
'streams',
]
6 changes: 3 additions & 3 deletions progressbar/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class Undefined(metaclass=FalseMeta):
assert TextIO is not None

__all__ = (
'FalseMeta',
'UnknownLength',
'Undefined',
'IO',
'FalseMeta',
'TextIO',
'Undefined',
'UnknownLength',
)
4 changes: 2 additions & 2 deletions progressbar/terminal/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ class SGR(CSI):
_start_code: int
_end_code: int
_code = 'm'
__slots__ = '_start_code', '_end_code'
__slots__ = '_end_code', '_start_code'

def __init__(self, start_code: int, end_code: int) -> None:
self._start_code = start_code
Expand All @@ -624,7 +624,7 @@ def __call__( # pyright: ignore[reportIncompatibleMethodOverride]


class SGRColor(SGR):
__slots__ = '_color', '_start_code', '_end_code'
__slots__ = '_color', '_end_code', '_start_code'

def __init__(self, color: Color, start_code: int, end_code: int) -> None:
self._color = color
Expand Down
2 changes: 1 addition & 1 deletion tests/original_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

def example(fn):
try:
name = 'Example %d' % int(fn.__name__[7:])
name = f'Example {int(fn.__name__[7:]):d}'
except Exception:
name = fn.__name__

Expand Down
2 changes: 1 addition & 1 deletion tests/test_monitor_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_generator_example(testdir) -> None:
pprint.pprint(result.stderr.lines, width=70)

lines = [
r'[/\\|\-]\s+\|\s*#\s*\| %(i)d Elapsed Time: \d:00:%(i)02d' % dict(i=i)
fr'[/\\|\-]\s+\|\s*#\s*\| {i:d} Elapsed Time: \d:00:{i:02d}'
for i in range(9)
]
result.stderr.re_match_lines(lines)
Expand Down
7 changes: 4 additions & 3 deletions tests/test_progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def test_dirty() -> None:


def test_negative_maximum() -> None:
with pytest.raises(ValueError), progressbar.ProgressBar(
max_value=-1
) as progress:
with (
pytest.raises(ValueError),
progressbar.ProgressBar(max_value=-1) as progress,
):
progress.start()

0 comments on commit 5488734

Please sign in to comment.