Skip to content

Commit 71f9b28

Browse files
committed
fix mypy and linter errors for spinners and progressbars
1 parent fe1d58b commit 71f9b28

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

src/pip/_internal/cli/progress_bars.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import itertools
44
import sys
5-
from signal import SIGINT, default_int_handler, signal, Signals
5+
from signal import SIGINT, Signals, default_int_handler, signal
66

77
from pip._vendor import six
88
from pip._vendor.progress.bar import Bar, FillingCirclesBar, IncrementalBar
@@ -14,7 +14,7 @@
1414
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
1515

1616
if MYPY_CHECK_RUNNING:
17-
from typing import Any, Dict, List, Iterator
17+
from typing import Any, Dict, List
1818
from types import FrameType
1919

2020
try:
@@ -79,7 +79,10 @@ def __init__(self, *args, **kwargs):
7979
"""
8080
Save the original SIGINT handler for later.
8181
"""
82-
super(InterruptibleMixin, self).__init__(*args, **kwargs) # type: ignore
82+
super(InterruptibleMixin, self).__init__( # type: ignore
83+
*args,
84+
**kwargs
85+
)
8386

8487
self.original_handler = signal(SIGINT, self.handle_sigint)
8588

@@ -99,19 +102,18 @@ def finish(self):
99102
This should happen regardless of whether the progress display finishes
100103
normally, or gets interrupted.
101104
"""
102-
super(InterruptibleMixin, self).finish() # type: ignore
105+
super(InterruptibleMixin, self).finish() # type: ignore
103106
signal(SIGINT, self.original_handler)
104107

105-
def handle_sigint(self, signum, frame):
106-
# type: (Signals, FrameType) -> None
108+
def handle_sigint(self, signum, frame): # type: ignore
107109
"""
108110
Call self.finish() before delegating to the original SIGINT handler.
109111
110112
This handler should only be in place while the progress display is
111113
active.
112114
"""
113115
self.finish()
114-
self.original_handler(signum, frame) # type: ignore
116+
self.original_handler(signum, frame)
115117

116118

117119
class SilentBar(Bar):
@@ -133,30 +135,35 @@ class DownloadProgressMixin(object):
133135

134136
def __init__(self, *args, **kwargs):
135137
# type: (List[Any], Dict[Any, Any]) -> None
136-
super(DownloadProgressMixin, self).__init__(*args, **kwargs) # type: ignore
137-
self.message = (" " * (get_indentation() + 2)) + self.message # type: str
138+
super(DownloadProgressMixin, self).__init__( # type: ignore
139+
*args,
140+
**kwargs
141+
)
142+
self.message = (" " * (
143+
get_indentation() + 2
144+
)) + self.message # type: str
138145

139146
@property
140147
def downloaded(self):
141148
# type: () -> str
142-
return format_size(self.index) # type: ignore
149+
return format_size(self.index) # type: ignore
143150

144151
@property
145152
def download_speed(self):
146153
# type: () -> str
147154
# Avoid zero division errors...
148-
if self.avg == 0.0: # type: ignore
155+
if self.avg == 0.0: # type: ignore
149156
return "..."
150-
return format_size(1 / self.avg) + "/s" # type: ignore
157+
return format_size(1 / self.avg) + "/s" # type: ignore
151158

152159
@property
153160
def pretty_eta(self):
154161
# type: () -> str
155-
if self.eta: # type: ignore
156-
return "eta {}".format(self.eta_td) # type: ignore
162+
if self.eta: # type: ignore
163+
return "eta {}".format(self.eta_td) # type: ignore
157164
return ""
158165

159-
def iter(self, it): # type: ignore
166+
def iter(self, it): # type: ignore
160167
for x in it:
161168
yield x
162169
self.next(len(x))
@@ -174,15 +181,15 @@ def __init__(self, *args, **kwargs):
174181
# is set in time. The base progress bar class writes the "hide cursor"
175182
# code to the terminal in its init, so if we don't set this soon
176183
# enough, we get a "hide" with no corresponding "show"...
177-
if WINDOWS and self.hide_cursor: # type: ignore
184+
if WINDOWS and self.hide_cursor: # type: ignore
178185
self.hide_cursor = False
179186

180-
super(WindowsMixin, self).__init__(*args, **kwargs) # type: ignore
187+
super(WindowsMixin, self).__init__(*args, **kwargs) # type: ignore
181188

182189
# Check if we are running on Windows and we have the colorama module,
183190
# if we do then wrap our file with it.
184191
if WINDOWS and colorama:
185-
self.file = colorama.AnsiToWin32(self.file) # type: ignore
192+
self.file = colorama.AnsiToWin32(self.file) # type: ignore
186193
# The progress code expects to be able to call self.file.isatty()
187194
# but the colorama.AnsiToWin32() object doesn't have that, so we'll
188195
# add it.
@@ -234,7 +241,7 @@ class DownloadProgressSpinner(WindowsMixin, InterruptibleMixin,
234241
file = sys.stdout
235242
suffix = "%(downloaded)s %(download_speed)s"
236243

237-
def next_phase(self): # type: ignore
244+
def next_phase(self): # type: ignore
238245
if not hasattr(self, "_phaser"):
239246
self._phaser = itertools.cycle(self.phases)
240247
return next(self._phaser)
@@ -264,7 +271,7 @@ def update(self):
264271
}
265272

266273

267-
def DownloadProgressProvider(progress_bar, max=None): # type: ignore
274+
def DownloadProgressProvider(progress_bar, max=None): # type: ignore
268275
if max is None or max == 0:
269276
return BAR_TYPES[progress_bar][1]().iter
270277
else:

src/pip/_internal/cli/spinners.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
1414

1515
if MYPY_CHECK_RUNNING:
16-
from typing import Iterator, IO, Any
16+
from typing import Iterator, IO
1717

1818
logger = logging.getLogger(__name__)
1919

src/pip/_internal/operations/build/wheel_legacy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os.path
33

4+
from pip._internal.cli.spinners import open_spinner
45
from pip._internal.utils.setuptools_build import (
56
make_setuptools_bdist_wheel_args,
67
)
@@ -10,7 +11,6 @@
1011
format_command_args,
1112
)
1213
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
13-
from pip._internal.cli.spinners import open_spinner
1414

1515
if MYPY_CHECK_RUNNING:
1616
from typing import List, Optional, Text

src/pip/_internal/utils/subprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from pip._vendor.six.moves import shlex_quote
1111

12-
from pip._internal.cli.spinners import open_spinner, SpinnerInterface
12+
from pip._internal.cli.spinners import SpinnerInterface, open_spinner
1313
from pip._internal.exceptions import InstallationError
1414
from pip._internal.utils.compat import console_to_str, str_to_display
1515
from pip._internal.utils.logging import subprocess_logger

0 commit comments

Comments
 (0)