Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Feb 14, 2022
1 parent 72183b4 commit e4c2883
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions tqdm/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, unit='it
total_fmt = str(total) if total is not None else '?'

try:
postfix = ', ' + postfix if postfix else ''
postfix = f', {postfix}' if postfix else ''
except TypeError:
pass

Expand All @@ -473,7 +473,7 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, unit='it
if prefix:
# old prefix setup work around
bool_prefix_colon_already = (prefix[-2:] == ": ")
l_bar = prefix if bool_prefix_colon_already else prefix + ": "
l_bar = prefix if bool_prefix_colon_already else f'{prefix}: '
else:
l_bar = ''

Expand Down Expand Up @@ -600,12 +600,12 @@ def _decr_instances(cls, instance):
# else:
if not instance.gui:
last = (instance.nrows or 20) - 1
# find unfixed (`pos >= 0`) overflow (`pos >= nrows - 1`)
instances = list(filter(
lambda i: hasattr(i, "pos") and last <= i.pos,
cls._instances))
# set first found to current `pos`
if instances:
if instances := list(
filter(
lambda i: hasattr(i, "pos") and last <= i.pos,
cls._instances,
)
):
inst = min(instances, key=lambda i: i.pos)
inst.clear(nolock=True)
inst.pos = abs(instance.pos)
Expand Down Expand Up @@ -1020,20 +1020,22 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None,
# Preprocess the arguments
if (
(ncols is None or nrows is None) and (file in (sys.stderr, sys.stdout))
) or dynamic_ncols: # pragma: no cover
): # pragma: no cover
if dynamic_ncols:
dynamic_ncols = _screen_shape_wrapper()
if dynamic_ncols:
ncols, nrows = dynamic_ncols(file)
else:
_dynamic_ncols = _screen_shape_wrapper()
if _dynamic_ncols:
_ncols, _nrows = _dynamic_ncols(file)
if ncols is None:
ncols = _ncols
if nrows is None:
nrows = _nrows

elif _dynamic_ncols := _screen_shape_wrapper():
_ncols, _nrows = _dynamic_ncols(file)
if ncols is None:
ncols = _ncols
if nrows is None:
nrows = _nrows

elif dynamic_ncols: # pragma: no cover
dynamic_ncols = _screen_shape_wrapper()
if dynamic_ncols:
ncols, nrows = dynamic_ncols(file)
if miniters is None:
miniters = 0
dynamic_miniters = True
Expand Down Expand Up @@ -1165,8 +1167,7 @@ def __iter__(self):
# If the bar is disabled, then just walk the iterable
# (note: keep this check outside the loop for performance)
if self.disable:
for obj in iterable:
yield obj
yield from iterable
return

mininterval = self.mininterval
Expand Down Expand Up @@ -1388,7 +1389,7 @@ def set_description(self, desc=None, refresh=True):
refresh : bool, optional
Forces refresh [default: True].
"""
self.desc = desc + ': ' if desc else ''
self.desc = f'{desc}: ' if desc else ''
if refresh:
self.refresh()

Expand Down Expand Up @@ -1424,8 +1425,10 @@ def set_postfix(self, ordered_dict=None, refresh=True, **kwargs):
postfix[key] = str(postfix[key])
# Else if it's a string, don't need to preprocess anything
# Stitch together to get the final postfix
self.postfix = ', '.join(key + '=' + postfix[key].strip()
for key in postfix.keys())
self.postfix = ', '.join(
f'{key}=' + postfix[key].strip() for key in postfix.keys()
)

if refresh:
self.refresh()

Expand Down

0 comments on commit e4c2883

Please sign in to comment.