8000 misc linting · tqdm/tqdm@4a442b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a442b4

Browse files
committed
misc linting
1 parent 7cb795d commit 4a442b4

File tree

8 files changed

+37
-44
lines changed

8 files changed

+37
-44
lines changed

.meta/.readme.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ with the ``desc`` and ``postfix`` arguments:
515515
sleep(0.1)
516516
517517
with tqdm(total=10, bar_format="{postfix[0]} {postfix[1][value]:>8.2g}",
518-
postfix=["Batch", dict(value=0)]) as t:
518+
postfix=["Batch", {"value": 0}]) as t:
519519 for i in range(10):
520520
sleep(0.1)
521521
t.postfix[1]["value"] = i / 2

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ with the ``desc`` and ``postfix`` arguments:
732732
sleep(0.1)
733733
734734
with tqdm(total=10, bar_format="{postfix[0]} {postfix[1][value]:>8.2g}",
735-
postfix=["Batch", dict(value=0)]) as t:
735+
postfix=["Batch", {"value": 0}]) as t:
736736
for i in range(10):
737737
sleep(0.1)
738738
t.postfix[1]["value"] = i / 2

examples/parallel_bars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
def progresser(n, auto_position=True, write_safe=False, blocking=True, progress=False):
1515
interval = random() * 0.002 / (NUM_SUBITERS - n + 2) # nosec
1616
total = 5000
17-
text = "#{0}, est. {1:<04.2}s".format(n, interval * total)
17+
text = f"#{n}, est. {interval * total:<04.2g}s"
1818
for _ in trange(total, desc=text, disable=not progress,
1919
lock_args=None if blocking else (False,),
2020
position=None if auto_position else n):

tests/conftest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ def pretest_posttest():
1818
n = len(tqdm._instances)
1919
if n:
2020
tqdm._instances.clear()
21-
raise EnvironmentError(
22-
"{0} `tqdm` instances still in existence PRE-test".format(n))
21+
raise EnvironmentError(f"{n} `tqdm` instances still in existence PRE-test")
2322
yield
2423
if getattr(tqdm, "_instances", False):
2524
n = len(tqdm._instances)
2625
if n:
2726
tqdm._instances.clear()
28-
raise EnvironmentError(
29-
"{0} `tqdm` instances still in existence POST-test".format(n))
27+
raise EnvironmentError(f"{n} `tqdm` instances still in existence POST-test")

tests/tests_pandas.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def test_pandas_rolling_expanding():
3939
our_file.seek(0)
4040
if our_file.getvalue().count(exres) < 2:
4141
our_file.seek(0)
42-
raise AssertionEr 9E88 ror("\nExpected:\n{0}\nIn:\n{1}\n".format(
43-
exres + " at least twice.", our_file.read()))
42+
raise AssertionError(
43+
f"\nExpected:\n{exres} at least twice.\nIn:\n{our_file.read()}\n")
4444

4545

4646
def test_pandas_series():
@@ -62,8 +62,8 @@ def test_pandas_series():
6262
our_file.seek(0)
6363
if our_file.getvalue().count(exres) < 2:
6464
our_file.seek(0)
65-
raise AssertionError("\nExpected:\n{0}\nIn:\n{1}\n".format(
66-
exres + " at least twice.", our_file.read()))
65+
raise AssertionError(
66+
f"\nExpected:\n{exres} at least twice.\nIn:\n{our_file.read()}\n")
6767

6868

6969
def test_pandas_data_frame():
@@ -94,17 +94,17 @@ def task_func(x):
9494
our_file.seek(0)
9595
if our_file.read().count('100%') < 3:
9696
our_file.seek(0)
97-
raise AssertionError("\nExpected:\n{0}\nIn:\n{1}\n".format(
98-
'100% at least three times', our_file.read()))
97+
raise AssertionError(
98+
f"\nExpected:\n100% at least three times\nIn:\n{our_file.read()}\n")
9999

100100
# apply_map, apply axis=0, apply axis=1
101101
expects = ['20000/20000', '200/200', '100/100']
102102
for exres in expects:
103103
our_file.seek(0)
104104
if our_file.getvalue().count(exres) < 1:
105105
our_file.seek(0)
106-
raise AssertionError("\nExpected:\n{0}\nIn:\n {1}\n".format(
107-
exres + " at least once.", our_file.read()))
106+
raise AssertionError(
107+
f"\nExpected:\n{exres} at least once.\nIn:\n{our_file.read()}\n")
108108

109109

110110
def test_pandas_groupby_apply():
@@ -130,8 +130,7 @@ def test_pandas_groupby_apply():
130130
nexres = '100%|##########|'
131131
if nexres in our_file.read():
132132
our_file.seek(0)
133-
raise AssertionError("\nDid not expect:\n{0}\nIn:{1}\n".format(
134-
nexres, our_file.read()))
133+
raise AssertionError(f"\nDid not expect:\n{nexres}\nIn:{our_file.read()}\n")
135134

136135
with closing(StringIO()) as our_file:
137136
tqdm.pandas(file=our_file, leave=True, ascii=True)
@@ -149,15 +148,15 @@ def test_pandas_groupby_apply():
149148
our_file.seek(0)
150149
if our_file.read().count('100%') < 4:
151150
our_file.seek(0)
152-
raise AssertionError("\nExpected:\n{0}\nIn:\n{1}\n".format(
153-
'100% at least four times', our_file.read()))
151+
raise AssertionError(
152+
f"\nExpected:\n100% at least four times\nIn:\n{our_file.read()}\n")
154153

155154
for exres in expects:
156155
our_file.seek(0)
157156
if our_file.getvalue().count(exres) < 1:
158157
our_file.seek(0)
159-
raise AssertionError("\nExpected:\n{0}\nIn:\n {1}\n".format(
160-
exres + " at least once.", our_file.read()))
158+
raise AssertionError(
159+
f"\nExpected:\n{exres} at least once.\nIn:\n{our_file.read()}\n")
161160

162161

163162
def test_pandas_leave():
@@ -172,8 +171,7 @@ def test_pandas_leave():
172171
exres = '100%|##########| 100/100'
173172
if exres not in our_file.read():
174173
our_file.seek(0)
175-
raise AssertionError("\nExpected:\n{0}\nIn:{1}\n".format(
176-
exres, our_file.read()))
174+
raise AssertionError(f"\nExpected:\n{exres}\nIn:{our_file.read()}\n")
177175

178176

179177
def test_pandas_apply_args_deprecation():

tests/tests_tqdm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,8 +936,7 @@ def test_close():
936936
res = our_file.getvalue()
937937
assert res[-1] == '\n'
938938
if not res.startswith(exres):
939-
raise AssertionError("\n<<< Expected:\n{0}\n>>> Got:\n{1}\n===".format(
940-
exres + ', ...it/s]\n', our_file.getvalue()))
939+
raise AssertionError(f"\n<<< Expected:\n{exres}, ...it/s]\n>>> Got:\n{res}\n===")
941940

942941
# Closing after the output stream has closed
943942
with closing(StringIO()) as our_file:

tqdm/cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ def main(fp=sys.stderr, argv=None):
199199
sys.stdout.write(d + '\n')
200200
sys.exit(0)
201201
elif argv and argv[0][:2] != '--':
202-
sys.stderr.write(
203-
"Error:Unknown argument:{0}\n{1}".format(argv[0], help_short))
202+
sys.stderr.write(f"Error:Unknown argument:{argv[0]}\n{help_short}")
204203

205204
argv = RE_SHLEX.split(' '.join(["tqdm"] + argv))
206205
opts = dict(zip(argv[1::3], argv[3::3]))

tqdm/std.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -474,26 +474,25 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, unit='it
474474
else:
475475
l_bar = ''
476476

477-
r_bar = '| {0}/{1} [{2}<{3}, {4}{5}]'.format(
478-
n_fmt, total_fmt, elapsed_str, remaining_str, rate_fmt, postfix)
477+
r_bar = f'| {n_fmt}/{total_fmt} [{elapsed_str}<{remaining_str}, {rate_fmt}{postfix}]'
479478

480479
# Custom bar formatting
481480
# Populate a dict with all available progress indicators
482-
format_dict = dict(
481+
format_dict = {
483482
# slight extension of self.format_dict
484-
n=n, n_fmt=n_fmt, total=total, total_fmt=total_fmt,
485-
elapsed=elapsed_str, elapsed_s=elapsed,
486-
ncols=ncols, desc=prefix or '', unit=unit,
487-
rate=inv_rate if inv_rate and inv_rate > 1 else rate,
488-
rate_fmt=rate_fmt, rate_noinv=rate,
489-
rate_noinv_fmt=rate_noinv_fmt, rate_inv=inv_rate,
490-
rate_inv_fmt=rate_inv_fmt,
491-
postfix=postfix, unit_divisor=unit_divisor,
492-
colour=colour,
483+
'n': n, 'n_fmt': n_fmt, 'total': total, 'total_fmt': total_fmt,
484+
'elapsed': elapsed_str, 'elapsed_s': elapsed,
485+
'ncols': ncols, 'desc': prefix or '', 'unit': unit,
486+
'rate': inv_rate if inv_rate and inv_rate > 1 else rate,
487+
'rate_fmt': rate_fmt, 'rate_noinv': rate,
488+
'rate_noinv_fmt': rate_noinv_fmt, 'rate_inv': inv_rate,
489+
'rate_inv_fmt': rate_inv_fmt,
490+
'postfix': postfix, 'unit_divisor': unit_divisor,
491+
'colour': colour,
493492
# plus more useful definitions
494-
remaining=remaining_str, remaining_s=remaining,
495-
l_bar=l_bar, r_bar=r_bar, eta=eta_dt,
496-
**extra_kwargs)
493+
'remaining': remaining_str, 'remaining_s': remaining,
494+
'l_bar': l_bar, 'r_bar': r_bar, 'eta': eta_dt,
495+
**extra_kwargs}
497496

498497
# total is known: we can predict some stats
499498
if total:
@@ -551,8 +550,8 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, unit='it
551550
return disp_trim(res, ncols) if ncols else res
552551
else:
553552
# no total: no progressbar, ETA, just progress stats
554-
return '{0}{1}{2} [{3}, {4}{5}]'.format(
555-
(prefix + ": ") if prefix else '', n_fmt, unit, elapsed_str, rate_fmt, postfix)
553+
return (f'{(prefix + ": ") if prefix else ""}'
554+
f'{n_fmt}{unit} [{elapsed_str}, {rate_fmt}{postfix}]')
556555

557556
def __new__(cls, *_, **__):
558557
instance = object.__new__(cls)

0 commit comments

Comments
 (0)
0