All type issues finally fixed? Maybe? · commit-0/python-progressbar@3cb06e5 · GitHub
Skip to content

Commit 3cb06e5

Browse files
committed
All type issues finally fixed? Maybe?
1 parent 9bda71d commit 3cb06e5

4 files changed

Lines changed: 50 additions & 34 deletions

File tree

progressbar/bar.py

Lines changed: 21 additions & 16 deletions

progressbar/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Undefined(metaclass=FalseMeta):
2020
pass
2121

2222

23-
try:
23+
try: # pragma: no cover
2424
IO = types.IO # type: ignore
2525
TextIO = types.TextIO # type: ignore
2626
except AttributeError:

progressbar/utils.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
assert scale_1024
2727
assert epoch
2828

29+
StringT = types.TypeVar('StringT', bound=types.StringTypes)
30+
2931
ANSI_TERMS = (
3032
'([xe]|bv)term',
3133
'(sco)?ansi',
@@ -141,7 +143,7 @@ def deltas_to_seconds(
141143
return default # type: ignore
142144

143145

144-
def no_color(value: types.StringTypes) -> types.StringTypes:
146+
def no_color(value: StringT) -> StringT:
145147
'''
146148
Return the `value` without ANSI escape codes
147149
@@ -153,9 +155,10 @@ def no_color(value: types.StringTypes) -> types.StringTypes:
153155
'abc'
154156
'''
155157
if isinstance(value, bytes):
156-
return re.sub('\\\u001b\\[.*?[@-~]'.encode(), b'', value)
158+
pattern: bytes = '\\\u001b\\[.*?[@-~]'.encode()
159+
return re.sub(pattern, b'', value) # type: ignore
157160
else:
158-
return re.sub(u'\x1b\\[.*?[@-~]', '', value)
161+
return re.sub(u'\x1b\\[.*?[@-~]', '', value) # type: ignore
159162

160163

161164
def len_color(value: types.StringTypes) -> int:
@@ -199,7 +202,7 @@ def __init__(
199202
self,
200203
target: base.IO,
201204
capturing: bool = False,
202-
listeners: types.Set[ProgressBar] = None,
205+
listeners: types.Optional[types.Set[ProgressBar]] = None,
203206
) -> None:
204207
self.buffer = io.StringIO()
205208
self.target = target
@@ -306,12 +309,17 @@ class StreamWrapper:
306309
stderr: base.TextIO | WrappingIO
307310
original_excepthook: types.Callable[
308311
[
309-
types.Optional[types.Type[BaseException]],
310-
types.Optional[BaseException],
311-
types.Optional[TracebackType],
312+
types.Type[BaseException],
313+
BaseException,
314+
TracebackType | None,
312315
],
313316
None,
314317
]
318+
# original_excepthook: types.Callable[
319+
# [
320+
# types.Type[BaseException],
321+
# BaseException, TracebackType | None,
322+
# ], None] | None
315323
wrapped_stdout: int = 0
316324
wrapped_stderr: int = 0
317325
wrapped_excepthook: int = 0
@@ -368,7 +376,7 @@ def wrap(self, stdout: bool = False, stderr: bool = False) -> None:
368376
if stderr:
369377
self.wrap_stderr()
370378

371-
def wrap_stdout(self) -> base.IO:
379+
def wrap_stdout(self) -> WrappingIO:
372380
self.wrap_excepthook()
373381

374382
if not self.wrapped_stdout:
@@ -377,9 +385,9 @@ def wrap_stdout(self) -> base.IO:
377385
)
378386
self.wrapped_stdout += 1
379387

380-
return sys.stdout
388+
return sys.stdout # type: ignore
381389

382-
def wrap_stderr(self) -> base.IO:
390+
def wrap_stderr(self) -> WrappingIO:
383391
self.wrap_excepthook()
384392

385393
if not self.wrapped_stderr:
@@ -388,7 +396,7 @@ def wrap_stderr(self) -> base.IO:
388396
)
389397
self.wrapped_stderr += 1
390398

391-
return sys.stderr
399+
return sys.stderr # type: ignore
392400

393401
def unwrap_excepthook(self) -> None:
394402
if self.wrapped_excepthook:

progressbar/widgets.py

Lines changed: 9 additions & 6 deletions

0 commit comments

Comments
 (0)