diff --git a/tqdm_5/tqdm/_tqdm.py b/tqdm_5/tqdm/_tqdm.py index 2ab2854..f0261da 100755 --- a/tqdm_5/tqdm/_tqdm.py +++ b/tqdm_5/tqdm/_tqdm.py @@ -748,19 +748,12 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, if disable is None and hasattr(file, "isatty") and not file.isatty(): disable = True - if total is None and iterable is not None: - try: - total = len(iterable) - except (TypeError, AttributeError): - total = None - if disable: self.iterable = iterable self.disable = disable self.pos = self._get_free_pos(self) self._instances.remove(self) self.n = initial - self.total = total return if kwargs: @@ -773,6 +766,12 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, else TqdmKeyError("Unknown argument(s): " + str(kwargs))) # Preprocess the arguments + if total is None and iterable is not None: + try: + total = len(iterable) + except (TypeError, AttributeError): + total = None + if ((ncols is None) and (file in (sys.stderr, sys.stdout))) or \ dynamic_ncols: # pragma: no cover if dynamic_ncols: diff --git a/tqdm_5/tqdm/tests/tests_tqdm.py b/tqdm_5/tqdm/tests/tests_tqdm.py index 35e1c70..baecaa3 100644 --- a/tqdm_5/tqdm/tests/tests_tqdm.py +++ b/tqdm_5/tqdm/tests/tests_tqdm.py @@ -1560,37 +1560,6 @@ def test_threading(): # TODO: test interleaved output #445 -@with_setup(pretest, posttest) -def test_bool(): - """Test boolean cast""" - def internal(our_file, disable): - with tqdm(total=10, file=our_file, disable=disable) as t: - assert t - with tqdm(total=0, file=our_file, disable=disable) as t: - assert not t - with trange(10, file=our_file, disable=disable) as t: - assert t - with trange(0, file=our_file, disable=disable) as t: - assert not t - with tqdm([], file=our_file, disable=disable) as t: - assert not t - with tqdm([0], file=our_file, disable=disable) as t: - assert t - with tqdm(file=our_file, disable=disable) as t: - try: - print(bool(t)) - except TypeError: - pass - else: - raise TypeError( - "Expected tqdm() with neither total nor iterable to fail") - - # test with and without disable - with closing(StringIO()) as our_file: - internal(our_file, False) - internal(our_file, True) - - @with_setup(pretest, posttest) def test_autonotebook(): """Test autonotebook fallback"""