mirror of https://github.com/tqdm/tqdm.git
add `asyncio.tarange`
This commit is contained in:
parent
6e0656f17f
commit
d3be02bc99
|
@ -1,6 +1,6 @@
|
|||
from .auto import tqdm as tqdm_auto
|
||||
__author__ = {"github.com/": ["casperdcl"]}
|
||||
__all__ = ['tqdm_asyncio', 'tqdm']
|
||||
__all__ = ['tqdm_asyncio', 'tarange', 'tqdm', 'trange']
|
||||
|
||||
|
||||
class tqdm_asyncio(tqdm_auto):
|
||||
|
@ -39,5 +39,13 @@ class tqdm_asyncio(tqdm_auto):
|
|||
raise
|
||||
|
||||
|
||||
def tarange(*args, **kwargs):
|
||||
"""
|
||||
A shortcut for `tqdm.asyncio.tqdm(range(*args), **kwargs)`.
|
||||
"""
|
||||
return tqdm_asyncio(range(*args), **kwargs)
|
||||
|
||||
|
||||
# Aliases
|
||||
tqdm = tqdm_asyncio
|
||||
trange = tarange
|
||||
|
|
|
@ -2,7 +2,7 @@ import asyncio
|
|||
from functools import partial
|
||||
|
||||
from tests_tqdm import with_setup, pretest, posttest, StringIO, closing
|
||||
from tqdm.asyncio import tqdm_asyncio
|
||||
from tqdm.asyncio import tqdm_asyncio, tarange
|
||||
|
||||
|
||||
def count(start=0, step=1):
|
||||
|
@ -18,6 +18,7 @@ def count(start=0, step=1):
|
|||
async def main():
|
||||
with closing(StringIO()) as our_file:
|
||||
tqdm = partial(tqdm_asyncio, file=our_file, miniters=0, mininterval=0)
|
||||
trange = partial(tarange, file=our_file, miniters=0, mininterval=0)
|
||||
|
||||
async for row in tqdm(count(), desc="counter"):
|
||||
if row >= 8:
|
||||
|
@ -32,7 +33,7 @@ async def main():
|
|||
our_file.seek(0)
|
||||
our_file.truncate()
|
||||
|
||||
async for row in tqdm(tqdm(range(9), desc="inner"), desc="outer"):
|
||||
async for row in tqdm(trange(9, desc="inner"), desc="outer"):
|
||||
pass
|
||||
assert 'inner: 100%' in our_file.getvalue()
|
||||
assert 'outer: 100%' in our_file.getvalue()
|
||||
|
|
Loading…
Reference in New Issue