mirror of https://github.com/tqdm/tqdm.git
misc linting
This commit is contained in:
parent
c2188cb3db
commit
800bc23e58
|
@ -265,7 +265,7 @@ class tqdm_notebook(std_tqdm):
|
|||
else:
|
||||
self.sp(close=True)
|
||||
|
||||
def moveto(self, *args, **kwargs):
|
||||
def moveto(self, *_, **__):
|
||||
# void -> avoid extraneous `\n` in IPython output cell
|
||||
return
|
||||
|
||||
|
|
17
tqdm/std.py
17
tqdm/std.py
|
@ -147,7 +147,7 @@ class Bar(object):
|
|||
CYAN='\x1b[36m', WHITE='\x1b[37m')
|
||||
|
||||
def __init__(self, frac, default_len=10, charset=UTF, colour=None):
|
||||
if not (0 <= frac <= 1):
|
||||
if not 0 <= frac <= 1:
|
||||
warn("clamping frac to range [0, 1]", TqdmWarning, stacklevel=2)
|
||||
frac = max(0, min(1, frac))
|
||||
assert default_len > 0
|
||||
|
@ -202,16 +202,11 @@ class Bar(object):
|
|||
bar_length, frac_bar_length = divmod(
|
||||
int(self.frac * N_BARS * nsyms), nsyms)
|
||||
|
||||
bar = charset[-1] * bar_length
|
||||
frac_bar = charset[frac_bar_length]
|
||||
|
||||
# whitespace padding
|
||||
if bar_length < N_BARS:
|
||||
bar = bar + frac_bar + \
|
||||
res = charset[-1] * bar_length
|
||||
if bar_length < N_BARS: # whitespace padding
|
||||
res = res + charset[frac_bar_length] + \
|
||||
charset[0] * (N_BARS - bar_length - 1)
|
||||
if self.colour:
|
||||
return self.colour + bar + self.COLOUR_RESET
|
||||
return bar
|
||||
return self.colour + res + self.COLOUR_RESET if self.colour else res
|
||||
|
||||
|
||||
class tqdm(Comparable):
|
||||
|
@ -546,7 +541,7 @@ class tqdm(Comparable):
|
|||
'{0}{1} [{2}, {3}{4}]'.format(
|
||||
n_fmt, unit, elapsed_str, rate_fmt, postfix)
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
def __new__(cls, *args, **_):
|
||||
# Create a new instance
|
||||
instance = object.__new__(cls)
|
||||
# Construct the lock if it does not exist
|
||||
|
|
|
@ -89,7 +89,7 @@ def retry_on_except(n=3):
|
|||
class MockIO(StringIO):
|
||||
"""Wraps StringIO to mock a file with no I/O"""
|
||||
|
||||
def write(self, data):
|
||||
def write(self, _):
|
||||
return
|
||||
|
||||
|
||||
|
@ -132,15 +132,15 @@ def simple_progress(iterable=None, total=None, file=sys.stdout, desc='',
|
|||
eta = (total - n[0]) / rate if rate > 0 else 0
|
||||
eta_fmt = format_interval(eta)
|
||||
|
||||
# bar = "#" * int(frac * width)
|
||||
# full_bar = "#" * int(frac * width)
|
||||
barfill = " " * int((1.0 - frac) * width)
|
||||
bar_length, frac_bar_length = divmod(int(frac * width * 10), 10)
|
||||
bar = '#' * bar_length
|
||||
full_bar = '#' * bar_length
|
||||
frac_bar = chr(48 + frac_bar_length) if frac_bar_length \
|
||||
else ' '
|
||||
|
||||
file.write("\r%s %i%%|%s%s%s| %i/%i [%s<%s, %s]" %
|
||||
(desc, percentage, bar, frac_bar, barfill, n[0],
|
||||
(desc, percentage, full_bar, frac_bar, barfill, n[0],
|
||||
total, spent_fmt, eta_fmt, rate_fmt))
|
||||
|
||||
if n[0] == total and leave:
|
||||
|
|
|
@ -969,14 +969,14 @@ def test_ascii():
|
|||
assert u"20%|\u2588\u2588" in res[3]
|
||||
|
||||
# Test custom bar
|
||||
for ascii in [" .oO0", " #"]:
|
||||
for bars in [" .oO0", " #"]:
|
||||
with closing(StringIO()) as our_file:
|
||||
for _ in tqdm(_range(len(ascii) - 1), file=our_file, miniters=1,
|
||||
mininterval=0, ascii=ascii, ncols=27):
|
||||
for _ in tqdm(_range(len(bars) - 1), file=our_file, miniters=1,
|
||||
mininterval=0, ascii=bars, ncols=27):
|
||||
pass
|
||||
res = our_file.getvalue().strip("\r").split("\r")
|
||||
for bar, line in zip(ascii, res):
|
||||
assert '|' + bar + '|' in line
|
||||
for b, line in zip(bars, res):
|
||||
assert '|' + b + '|' in line
|
||||
|
||||
|
||||
@with_setup(pretest, posttest)
|
||||
|
@ -1170,7 +1170,8 @@ Use `position` instead for manual control.""" not in our_file.getvalue():
|
|||
def test_bar_format():
|
||||
"""Test custom bar formatting"""
|
||||
with closing(StringIO()) as our_file:
|
||||
bar_format = r'{l_bar}{bar}|{n_fmt}/{total_fmt}-{n}/{total}{percentage}{rate}{rate_fmt}{elapsed}{remaining}' # NOQA
|
||||
bar_format = ('{l_bar}{bar}|{n_fmt}/{total_fmt}-{n}/{total}'
|
||||
'{percentage}{rate}{rate_fmt}{elapsed}{remaining}')
|
||||
for _ in trange(2, file=our_file, leave=True, bar_format=bar_format):
|
||||
pass
|
||||
out = our_file.getvalue()
|
||||
|
@ -1654,7 +1655,7 @@ def test_deprecation_exception():
|
|||
our_file, 'write', sys.stderr.write)))
|
||||
|
||||
def test_TqdmDeprecationWarning_nofpwrite():
|
||||
raise (TqdmDeprecationWarning('Test!', fp_write=None))
|
||||
raise TqdmDeprecationWarning('Test!', fp_write=None)
|
||||
|
||||
assert_raises(TqdmDeprecationWarning, test_TqdmDeprecationWarning)
|
||||
assert_raises(Exception, test_TqdmDeprecationWarning_nofpwrite)
|
||||
|
@ -1878,7 +1879,7 @@ def test_wrapattr():
|
|||
res = writer.getvalue()
|
||||
assert data == res
|
||||
res = our_file.getvalue()
|
||||
assert ('%.1fB [' % len(data)) in res
|
||||
assert '%.1fB [' % len(data) in res
|
||||
|
||||
with closing(StringIO()) as our_file:
|
||||
with closing(StringIO()) as writer:
|
||||
|
@ -1886,7 +1887,7 @@ def test_wrapattr():
|
|||
writer, "write", file=our_file, bytes=False) as wrap:
|
||||
wrap.write(data)
|
||||
res = our_file.getvalue()
|
||||
assert ('%dit [' % len(data)) in res
|
||||
assert '%dit [' % len(data) in res
|
||||
|
||||
|
||||
@with_setup(pretest, posttest)
|
||||
|
|
Loading…
Reference in New Issue