Skip to content

Commit

Permalink
misc linting
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Mar 3, 2023
1 parent 7cb795d commit 4a442b4
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .meta/.readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ with the ``desc`` and ``postfix`` arguments:
sleep(0.1)
with tqdm(total=10, bar_format="{postfix[0]} {postfix[1][value]:>8.2g}",
postfix=["Batch", dict(value=0)]) as t:
postfix=["Batch", {"value": 0}]) as t:
for i in range(10):
sleep(0.1)
t.postfix[1]["value"] = i / 2
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ with the ``desc`` and ``postfix`` arguments:
sleep(0.1)
with tqdm(total=10, bar_format="{postfix[0]} {postfix[1][value]:>8.2g}",
postfix=["Batch", dict(value=0)]) as t:
postfix=["Batch", {"value": 0}]) as t:
for i in range(10):
sleep(0.1)
t.postfix[1]["value"] = i / 2
Expand Down
2 changes: 1 addition & 1 deletion examples/parallel_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def progresser(n, auto_position=True, write_safe=False, blocking=True, progress=False):
interval = random() * 0.002 / (NUM_SUBITERS - n + 2) # nosec
total = 5000
text = "#{0}, est. {1:<04.2}s".format(n, interval * total)
text = f"#{n}, est. {interval * total:<04.2g}s"
for _ in trange(total, desc=text, disable=not progress,
lock_args=None if blocking else (False,),
position=None if auto_position else n):
Expand Down
6 changes: 2 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ def pretest_posttest():
n = len(tqdm._instances)
if n:
tqdm._instances.clear()
raise EnvironmentError(
"{0} `tqdm` instances still in existence PRE-test".format(n))
raise EnvironmentError(f"{n} `tqdm` instances still in existence PRE-test")
yield
if getattr(tqdm, "_instances", False):
n = len(tqdm._instances)
if n:
tqdm._instances.clear()
raise EnvironmentError(
"{0} `tqdm` instances still in existence POST-test".format(n))
raise EnvironmentError(f"{n} `tqdm` instances still in existence POST-test")
30 changes: 14 additions & 16 deletions tests/tests_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def test_pandas_rolling_expanding():
our_file.seek(0)
if our_file.getvalue().count(exres) < 2:
our_file.seek(0)
raise AssertionError("\nExpected:\n{0}\nIn:\n{1}\n".format(
exres + " at least twice.", our_file.read()))
raise AssertionError(
f"\nExpected:\n{exres} at least twice.\nIn:\n{our_file.read()}\n")


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


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

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


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

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

for exres in expects:
our_file.seek(0)
if our_file.getvalue().count(exres) < 1:
our_file.seek(0)
raise AssertionError("\nExpected:\n{0}\nIn:\n {1}\n".format(
exres + " at least once.", our_file.read()))
raise AssertionError(
f"\nExpected:\n{exres} at least once.\nIn:\n{our_file.read()}\n")


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


def test_pandas_apply_args_deprecation():
Expand Down
3 changes: 1 addition & 2 deletions tests/tests_tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,7 @@ def test_close():
res = our_file.getvalue()
assert res[-1] == '\n'
if not res.startswith(exres):
raise AssertionError("\n<<< Expected:\n{0}\n>>> Got:\n{1}\n===".format(
exres + ', ...it/s]\n', our_file.getvalue()))
raise AssertionError(f"\n<<< Expected:\n{exres}, ...it/s]\n>>> Got:\n{res}\n===")

# Closing after the output stream has closed
with closing(StringIO()) as our_file:
Expand Down
3 changes: 1 addition & 2 deletions tqdm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ def main(fp=sys.stderr, argv=None):
sys.stdout.write(d + '\n')
sys.exit(0)
elif argv and argv[0][:2] != '--':
sys.stderr.write(
"Error:Unknown argument:{0}\n{1}".format(argv[0], help_short))
sys.stderr.write(f"Error:Unknown argument:{argv[0]}\n{help_short}")

argv = RE_SHLEX.split(' '.join(["tqdm"] + argv))
opts = dict(zip(argv[1::3], argv[3::3]))
Expand Down
33 changes: 16 additions & 17 deletions tqdm/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,26 +474,25 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, unit='it
else:
l_bar = ''

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

# Custom bar formatting
# Populate a dict with all available progress indicators
format_dict = dict(
format_dict = {
# slight extension of self.format_dict
n=n, n_fmt=n_fmt, total=total, total_fmt=total_fmt,
elapsed=elapsed_str, elapsed_s=elapsed,
ncols=ncols, desc=prefix or '', unit=unit,
rate=inv_rate if inv_rate and inv_rate > 1 else rate,
rate_fmt=rate_fmt, rate_noinv=rate,
rate_noinv_fmt=rate_noinv_fmt, rate_inv=inv_rate,
rate_inv_fmt=rate_inv_fmt,
postfix=postfix, unit_divisor=unit_divisor,
colour=colour,
'n': n, 'n_fmt': n_fmt, 'total': total, 'total_fmt': total_fmt,
'elapsed': elapsed_str, 'elapsed_s': elapsed,
'ncols': ncols, 'desc': prefix or '', 'unit': unit,
'rate': inv_rate if inv_rate and inv_rate > 1 else rate,
'rate_fmt': rate_fmt, 'rate_noinv': rate,
'rate_noinv_fmt': rate_noinv_fmt, 'rate_inv': inv_rate,
'rate_inv_fmt': rate_inv_fmt,
'postfix': postfix, 'unit_divisor': unit_divisor,
'colour': colour,
# plus more useful definitions
remaining=remaining_str, remaining_s=remaining,
l_bar=l_bar, r_bar=r_bar, eta=eta_dt,
**extra_kwargs)
'remaining': remaining_str, 'remaining_s': remaining,
'l_bar': l_bar, 'r_bar': r_bar, 'eta': eta_dt,
**extra_kwargs}

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

def __new__(cls, *_, **__):
instance = object.__new__(cls)
Expand Down

0 comments on commit 4a442b4

Please sign in to comment.