diff --git a/tests/tests_asyncio.py b/tests/tests_asyncio.py index 5311701..513066d 100644 --- a/tests/tests_asyncio.py +++ b/tests/tests_asyncio.py @@ -120,6 +120,26 @@ async def test_as_completed(capsys, tol): raise +@mark.asyncio +async def test_as_completed_unsized(capsys): + """Test asyncio as_completed with an unsized iterable""" + fs = (asyncio.sleep(0, result=i) for i in range(3)) + res = sorted([await f for f in as_completed(fs)]) + assert res == [0, 1, 2] + _, err = capsys.readouterr() + assert '3it' in err + + +@mark.asyncio +async def test_as_completed_unsized_with_total(capsys): + """Test asyncio as_completed with an unsized iterable and an explicit total""" + fs = (asyncio.sleep(0, result=i) for i in range(3)) + res = sorted([await f for f in as_completed(fs, total=3)]) + assert res == [0, 1, 2] + _, err = capsys.readouterr() + assert '3/3' in err + + async def double(i): return i * 2 diff --git a/tqdm/asyncio.py b/tqdm/asyncio.py index ac5c2e6..df7ef5a 100644 --- a/tqdm/asyncio.py +++ b/tqdm/asyncio.py @@ -64,7 +64,10 @@ class tqdm_asyncio(std_tqdm): Wrapper for `asyncio.as_completed`. """ if total is None: - total = len(fs) + try: + total = len(fs) + except (TypeError, AttributeError): + total = None kwargs = {} if version_info[:2] < (3, 10): kwargs['loop'] = loop