Support for Python 3.8

This commit is contained in:
Profitroll 2023-08-14 10:46:25 +02:00
parent d82756e0c6
commit 2b2222bedb
Signed by: profitroll
GPG Key ID: FA35CAB49DACD3B2
3 changed files with 38 additions and 19 deletions

View File

@ -46,7 +46,6 @@ if TYPE_CHECKING:
class CommandCursor(_CommandCursor, Generic[_DocumentType]):
_CommandCursor__data: Deque[Any]
_CommandCursor__killed: bool
@ -184,13 +183,17 @@ class AsyncLatentCommandCursor(AsyncCommandCursor):
return self
def _get_more(self) -> Union[asyncio.Future[int], Coroutine[Any, Any, int]]:
def _get_more(self) -> Union["asyncio.Future[int]", Coroutine[Any, Any, int]]:
if not self.started:
self.started = True
original_future = self.loop.create_future()
future = self.loop.create_task(run_sync(self.start, *self.args, **self.kwargs))
future = self.loop.create_task(
run_sync(self.start, *self.args, **self.kwargs)
)
future.add_done_callback(
partial(self.loop.call_soon_threadsafe, self._on_started, original_future)
partial(
self.loop.call_soon_threadsafe, self._on_started, original_future
)
)
self.start, self.args, self.kwargs = lambda _: None, (), {}
@ -201,8 +204,8 @@ class AsyncLatentCommandCursor(AsyncCommandCursor):
def _on_started(
self,
original_future: asyncio.Future[int],
future: asyncio.Future[Union[CommandCursor, RawBatchCommandCursor]],
original_future: "asyncio.Future[int]",
future: "asyncio.Future[Union[CommandCursor, RawBatchCommandCursor]]",
) -> None:
try:
self.dispatch = future.result()
@ -214,7 +217,9 @@ class AsyncLatentCommandCursor(AsyncCommandCursor):
if original_future.done():
return
if self.dispatch._CommandCursor__data or not self.dispatch.alive: # skipcq: PYL-W0212
if (
self.dispatch._CommandCursor__data or not self.dispatch.alive
): # skipcq: PYL-W0212
# _get_more is complete.
original_future.set_result(
len(self.dispatch._CommandCursor__data) # skipcq: PYL-W0212
@ -223,7 +228,7 @@ class AsyncLatentCommandCursor(AsyncCommandCursor):
# Send a getMore.
fut = self.loop.create_task(super()._get_more())
def copy(f: asyncio.Future[int]) -> None:
def copy(f: "asyncio.Future[int]") -> None:
if original_future.done():
return

View File

@ -55,7 +55,9 @@ class AsyncCursorBase(AsyncBase, Generic[_DocumentType]):
And we now have :meth:`~to_list()` so yeah kinda useless
"""
collection: Optional[Union["AsyncCollection[_DocumentType]", Collection[_DocumentType]]]
collection: Optional[
Union["AsyncCollection[_DocumentType]", Collection[_DocumentType]]
]
dispatch: Union[
"_LatentCursor[_DocumentType]",
"CommandCursor[_DocumentType]",
@ -113,7 +115,8 @@ class AsyncCursorBase(AsyncBase, Generic[_DocumentType]):
def _get_more(self) -> Coroutine[Any, Any, int]:
if not self.alive:
raise InvalidOperation(
"Can't call get_more() on a AsyncCursor that has been" " exhausted or killed."
"Can't call get_more() on a AsyncCursor that has been"
" exhausted or killed."
)
self.started = True
@ -123,8 +126,8 @@ class AsyncCursorBase(AsyncBase, Generic[_DocumentType]):
self,
length: Optional[int],
the_list: List[Mapping[str, Any]],
future: asyncio.Future[List[Mapping[str, Any]]],
get_more_future: asyncio.Future[int],
future: "asyncio.Future[List[Mapping[str, Any]]]",
get_more_future: "asyncio.Future[int]",
) -> None:
# get_more_future is the result of self._get_more().
# future will be the result of the user's to_list() call.
@ -150,7 +153,13 @@ class AsyncCursorBase(AsyncBase, Generic[_DocumentType]):
else:
new_future = self.loop.create_task(self._get_more())
new_future.add_done_callback(
partial(self.loop.call_soon_threadsafe, self._to_list, length, the_list, future)
partial(
self.loop.call_soon_threadsafe,
self._to_list,
length,
the_list,
future,
)
)
except Exception as exc: # skipcq: PYL-W0703
if not future.done():
@ -173,7 +182,9 @@ class AsyncCursorBase(AsyncBase, Generic[_DocumentType]):
return await run_sync(next, self.dispatch)
raise StopAsyncIteration
def to_list(self, length: Optional[int] = None) -> asyncio.Future[List[Mapping[str, Any]]]:
def to_list(
self, length: Optional[int] = None
) -> "asyncio.Future[List[Mapping[str, Any]]]":
if length is not None and length < 0:
raise ValueError("length must be non-negative")
@ -193,7 +204,9 @@ class AsyncCursorBase(AsyncBase, Generic[_DocumentType]):
get_more_future = self.loop.create_task(get_more_future)
get_more_future.add_done_callback(
partial(self.loop.call_soon_threadsafe, self._to_list, length, the_list, future)
partial(
self.loop.call_soon_threadsafe, self._to_list, length, the_list, future
)
)
return future

View File

@ -1,12 +1,12 @@
[tool.poetry]
name = "async-pymongo"
version = "0.1.3"
version = "0.1.4"
description = "Asynchronous wrapper for pymongo"
license = "GPL-3.0-or-later"
authors = [
"Adek Maulana <adekzmaulana@gmail.com>",
"Gaung Ramadhan <hi@mrmiss.my.id>",
"wulan17 <wulan17@nusantararom.org>"
"wulan17 <wulan17@nusantararom.org>",
]
readme = "README.md"
repository = "https://github.com/Mayuri-Chan/async_pymongo"
@ -17,6 +17,7 @@ classifiers = [
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
@ -27,7 +28,7 @@ classifiers = [
packages = [{ include = "async_pymongo" }]
[tool.poetry.dependencies]
python = "~=3.9"
python = "~=3.8"
pymongo = "^4.3.3"