Skip to content

Commit 859fcd1

Browse files
committed
Fixed basic tox/pytest runs
1 parent d6e2849 commit 859fcd1

8 files changed

Lines changed: 329 additions & 300 deletions

File tree

progressbar/bar.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
T = types.TypeVar('T')
3636

37+
3738
class ProgressBarMixinBase(abc.ABC):
3839
_started = False
3940
_finished = False
@@ -184,7 +185,7 @@ class DefaultFdMixin(ProgressBarMixinBase):
184185

185186
def __init__(
186187
self,
187-
fd: base.IO[str] = sys.stderr,
188+
fd: base.TextIO = sys.stderr,
188189
is_terminal: bool | None = None,
189190
line_breaks: bool | None = None,
190191
enable_colors: progressbar.env.ColorSupport | None = None,
@@ -205,11 +206,12 @@ def __init__(
205206

206207
super().__init__(**kwargs)
207208

208-
def _apply_line_offset(self, fd: base.IO[T], line_offset: int) -> base.IO[T]:
209+
def _apply_line_offset(
210+
self, fd: base.TextIO, line_offset: int
211+
) -> base.TextIO:
209212
if line_offset:
210213
return progressbar.terminal.stream.LineOffsetStreamWrapper(
211-
line_offset,
212-
types.cast(base.TextIO, fd),
214+
line_offset, fd,
213215
)
214216
else:
215217
return fd
@@ -280,7 +282,7 @@ def update(self, *args: types.Any, **kwargs: types.Any) -> None:
280282
try: # pragma: no cover
281283
self.fd.write(line)
282284
except UnicodeEncodeError: # pragma: no cover
283-
self.fd.write(line.encode('ascii', 'replace'))
285+
self.fd.write(types.cast(str, line.encode('ascii', 'replace')))
284286

285287
def finish(
286288
self,
@@ -921,7 +923,7 @@ def _update_parents(self, value):
921923
# Only flush if something was actually written
922924
self.fd.flush()
923925

924-
def start(self, max_value=None, init=True):
926+
def start(self, max_value=None, init=True, *args, **kwargs):
925927
'''Starts measuring time, and prints the bar at 0%.
926928
927929
It returns self so you can use it like this:
@@ -952,9 +954,9 @@ def start(self, max_value=None, init=True):
952954
if self.max_value is None:
953955
self.max_value = self._DEFAULT_MAXVAL
954956

955-
StdRedirectMixin.start(self, max_value=max_value)
956-
ResizableMixin.start(self, max_value=max_value)
957-
ProgressBarBase.start(self, max_value=max_value)
957+
StdRedirectMixin.start(self, max_value=max_value, *args, **kwargs)
958+
ResizableMixin.start(self, max_value=max_value, *args, **kwargs)
959+
ProgressBarBase.start(self, max_value=max_value, *args, **kwargs)
958960

959961
# Constructing the default widgets is only done when we know max_value
960962
if not self.widgets:

progressbar/multi.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,22 @@ class MultiBar(typing.Dict[str, bar.ProgressBar]):
7575
_thread_closed: threading.Event = threading.Event()
7676

7777
def __init__(
78-
self,
79-
bars: typing.Iterable[tuple[str, bar.ProgressBar]] | None = None,
80-
fd: typing.TextIO = sys.stderr,
81-
prepend_label: bool = True,
82-
append_label: bool = False,
83-
label_format='{label:20.20} ',
84-
initial_format: str | None = '{label:20.20} Not yet started',
85-
finished_format: str | None = None,
86-
update_interval: float = 1 / 60.0, # 60fps
87-
show_initial: bool = True,
88-
show_finished: bool = True,
89-
remove_finished: timedelta | float = timedelta(seconds=3600),
90-
sort_key: str | SortKey = SortKey.CREATED,
91-
sort_reverse: bool = True,
92-
sort_keyfunc: SortKeyFunc | None = None,
93-
**progressbar_kwargs,
78+
self,
79+
bars: typing.Iterable[tuple[str, bar.ProgressBar]] | None = None,
80+
fd: typing.TextIO = sys.stderr,
81+
prepend_label: bool = True,
82+
append_label: bool = False,
83+
label_format='{label:20.20} ',
84+
initial_format: str | None = '{label:20.20} Not yet started',
85+
finished_format: str | None = None,
86+
update_interval: float = 1 / 60.0, # 60fps
87+
show_initial: bool = True,
88+
show_finished: bool = True,
89+
remove_finished: timedelta | float = timedelta(seconds=3600),
90+
sort_key: str | SortKey = SortKey.CREATED,
91+
sort_reverse: bool = True,
92+
sort_keyfunc: SortKeyFunc | None = None,
93+
**progressbar_kwargs,
9494
):
9595
self.fd = fd
9696

@@ -197,11 +197,11 @@ def render(self, flush: bool = True, force: bool = False):
197197
self._buffer.write('\n')
198198

199199
for i, (previous, current) in enumerate(
200-
itertools.zip_longest(
201-
self._previous_output,
202-
output,
203-
fillvalue='',
204-
),
200+
itertools.zip_longest(
201+
self._previous_output,
202+
output,
203+
fillvalue='',
204+
),
205205
):
206206
if previous != current or force: # pragma: no branch
207207
self.print(
@@ -218,10 +218,10 @@ def render(self, flush: bool = True, force: bool = False):
218218
self.flush()
219219

220220
def _render_bar(
221-
self,
222-
bar_: bar.ProgressBar,
223-
now,
224-
expired,
221+
self,
222+
bar_: bar.ProgressBar,
223+
now,
224+
expired,
225225
) -> typing.Iterable[str]:
226226
def update(force=True, write=True): # pragma: no cover
227227
self._label_bar(bar_)
@@ -242,21 +242,21 @@ def update(force=True, write=True): # pragma: no cover
242242
yield self.initial_format.format(label=bar_.label)
243243

244244
def _render_finished_bar(
245-
self,
246-
bar_: bar.ProgressBar,
247-
now,
248-
expired,
249-
update,
245+
self,
246+
bar_: bar.ProgressBar,
247+
now,
248+
expired,
249+
update,
250250
) -> typing.Iterable[str]:
251251
if bar_ not in self._finished_at:
252252
self._finished_at[bar_] = now
253253
# Force update to get the finished format
254254
update(write=False)
255255

256256
if (
257-
self.remove_finished
258-
and expired is not None
259-
and expired >= self._finished_at[bar_]
257+
self.remove_finished
258+
and expired is not None
259+
and expired >= self._finished_at[bar_]
260260
):
261261
del self[bar_.label]
262262
return
@@ -271,13 +271,13 @@ def _render_finished_bar(
271271
yield self.finished_format.format(label=bar_.label)
272272

273273
def print(
274-
self,
275-
*args,
276-
end='\n',
277-
offset=None,
278-
flush=True,
279-
clear=True,
280-
**kwargs,
274+
self,
275+
*args,
276+
end='\n',
277+
offset=None,
278+
flush=True,
279+
clear=True,
280+
**kwargs,
281281
):
282282
'''
283283
Print to the progressbar stream without overwriting the progressbars.

progressbar/terminal/stream.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import sys
4+
import typing
45
from types import TracebackType
56
from typing import Iterable, Iterator
67

@@ -23,16 +24,16 @@ def flush(self) -> None:
2324
def isatty(self) -> bool:
2425
return self.stream.isatty()
2526

26-
def read(self, __n: int = -1) -> str:
27+
def read(self, __n: int = -1) -> typing.AnyStr:
2728
return self.stream.read(__n)
2829

2930
def readable(self) -> bool:
3031
return self.stream.readable()
3132

32-
def readline(self, __limit: int = -1) -> str:
33+
def readline(self, __limit: int = -1) -> typing.AnyStr:
3334
return self.stream.readline(__limit)
3435

35-
def readlines(self, __hint: int = -1) -> list[str]:
36+
def readlines(self, __hint: int = -1) -> list[typing.AnyStr]:
3637
return self.stream.readlines(__hint)
3738

3839
def seek(self, __offset: int, __whence: int = 0) -> int:
@@ -50,13 +51,13 @@ def truncate(self, __size: int | None = None) -> int:
5051
def writable(self) -> bool:
5152
return self.stream.writable()
5253

53-
def writelines(self, __lines: Iterable[str]) -> None:
54+
def writelines(self, __lines: Iterable[typing.AnyStr]) -> None:
5455
return self.stream.writelines(__lines)
5556

56-
def __next__(self) -> str:
57+
def __next__(self) -> typing.AnyStr:
5758
return self.stream.__next__()
5859

59-
def __iter__(self) -> Iterator[str]:
60+
def __iter__(self) -> Iterator[typing.AnyStr]:
6061
return self.stream.__iter__()
6162

6263
def __exit__(
@@ -93,28 +94,29 @@ def write(self, data):
9394

9495

9596
class LastLineStream(TextIOOutputWrapper):
96-
line: str = ''
97+
line: typing.AnyStr = ''
9798

9899
def seekable(self) -> bool:
99100
return False
100101

101102
def readable(self) -> bool:
102103
return True
103104

104-
def read(self, __n: int = -1) -> str:
105+
def read(self, __n: int = -1) -> typing.AnyStr:
105106
if __n < 0:
106107
return self.line
107108
else:
108109
return self.line[:__n]
109110

110-
def readline(self, __limit: int = -1) -> str:
111+
def readline(self, __limit: int = -1) -> typing.AnyStr:
111112
if __limit < 0:
112113
return self.line
113114
else:
114115
return self.line[:__limit]
115116

116-
def write(self, data):
117+
def write(self, data: typing.AnyStr) -> int:
117118
self.line = data
119+
return len(data)
118120

119121
def truncate(self, __size: int | None = None) -> int:
120122
if __size is None:
@@ -124,10 +126,11 @@ def truncate(self, __size: int | None = None) -> int:
124126

125127
return len(self.line)
126128

127-
def __iter__(self) -> Iterator[str]:
129+
def __iter__(self) -> typing.Generator[typing.AnyStr, typing.Any,
130+
typing.Any]:
128131
yield self.line
129132

130-
def writelines(self, __lines: Iterable[str]) -> None:
133+
def writelines(self, __lines: Iterable[typing.AnyStr]) -> None:
131134
line = ''
132135
# Walk through the lines and take the last one
133136
for line in __lines: # noqa: B007

0 commit comments

Comments
 (0)