Skip to content

Commit

Permalink
chore: type hinting some of async library of mightstone
Browse files Browse the repository at this point in the history
  • Loading branch information
Guibod committed Mar 4, 2023
1 parent b17cd2b commit 44639fd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/mightstone/ass/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import asyncio
import logging
from typing import Any, AsyncGenerator, List, TypeVar

import nest_asyncio
from aiostream import pipe, stream

logger = logging.getLogger(__name__)

T = TypeVar("T")


def asyncio_run(future, as_task=True):
"""
Expand All @@ -31,14 +34,14 @@ def _to_task(future, as_task, loop):
return loop.create_task(future)


def stream_as_list(ait, limit=100):
def stream_as_list(ait: AsyncGenerator[T, Any], limit=100) -> List[T]:
async def run(my_it):
return await (stream.iterate(my_it) | pipe.take(limit) | pipe.list())

return asyncio_run(run(ait))


def stream_print(ait, limit=100):
def stream_print(ait: AsyncGenerator[T, Any], limit=100):
async def run(my_it):
await (stream.iterate(my_it) | pipe.take(limit) | pipe.print())

Expand Down
4 changes: 2 additions & 2 deletions src/mightstone/ass/compressor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
see: https://github.com/chimpler/async-stream
"""
from typing import Iterable, Optional
from typing import Any, AsyncIterable, Iterable, Optional, Union

from mightstone.ass.compressor.async_file_obj import AsyncFileObj
from mightstone.ass.compressor.async_reader import AsyncReader
from mightstone.ass.compressor.async_writer import AsyncWriter


def open(
afd: str,
afd: Union[AsyncIterable[bytes], Any],
mode=None,
encoding=None,
compression=None,
Expand Down
4 changes: 2 additions & 2 deletions src/mightstone/ass/compressor/async_file_obj.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import AsyncIterable, Optional
from typing import AsyncIterable, Optional, Union

from mightstone.ass.compressor.codecs import error_import_usage

Expand All @@ -10,7 +10,7 @@ class AsyncFileObj(object):

def __init__(
self,
afd,
afd: Union[AsyncIterable[bytes]],
mode,
compressor,
decompressor,
Expand Down

0 comments on commit 44639fd

Please sign in to comment.