From 2b2222bedbc11a79b217793175f5620dc25bf0ed Mon Sep 17 00:00:00 2001 From: profitroll Date: Mon, 14 Aug 2023 10:46:25 +0200 Subject: [PATCH] Support for Python 3.8 --- async_pymongo/command_cursor.py | 21 +++++++++++++-------- async_pymongo/cursor_base.py | 27 ++++++++++++++++++++------- pyproject.toml | 9 +++++---- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/async_pymongo/command_cursor.py b/async_pymongo/command_cursor.py index 3c8a811..840da29 100644 --- a/async_pymongo/command_cursor.py +++ b/async_pymongo/command_cursor.py @@ -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 diff --git a/async_pymongo/cursor_base.py b/async_pymongo/cursor_base.py index 41633f5..ebcd786 100644 --- a/async_pymongo/cursor_base.py +++ b/async_pymongo/cursor_base.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 3143b8e..f20ee89 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 ", "Gaung Ramadhan ", - "wulan17 " + "wulan17 ", ] 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", @@ -24,10 +25,10 @@ classifiers = [ "Topic :: Database", ] -packages = [{include = "async_pymongo"}] +packages = [{ include = "async_pymongo" }] [tool.poetry.dependencies] -python = "~=3.9" +python = "~=3.8" pymongo = "^4.3.3"