Support for Python 3.8
This commit is contained in:
parent
d82756e0c6
commit
2b2222bedb
@ -46,7 +46,6 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
|
|
||||||
class CommandCursor(_CommandCursor, Generic[_DocumentType]):
|
class CommandCursor(_CommandCursor, Generic[_DocumentType]):
|
||||||
|
|
||||||
_CommandCursor__data: Deque[Any]
|
_CommandCursor__data: Deque[Any]
|
||||||
_CommandCursor__killed: bool
|
_CommandCursor__killed: bool
|
||||||
|
|
||||||
@ -184,13 +183,17 @@ class AsyncLatentCommandCursor(AsyncCommandCursor):
|
|||||||
|
|
||||||
return self
|
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:
|
if not self.started:
|
||||||
self.started = True
|
self.started = True
|
||||||
original_future = self.loop.create_future()
|
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(
|
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, (), {}
|
self.start, self.args, self.kwargs = lambda _: None, (), {}
|
||||||
@ -201,8 +204,8 @@ class AsyncLatentCommandCursor(AsyncCommandCursor):
|
|||||||
|
|
||||||
def _on_started(
|
def _on_started(
|
||||||
self,
|
self,
|
||||||
original_future: asyncio.Future[int],
|
original_future: "asyncio.Future[int]",
|
||||||
future: asyncio.Future[Union[CommandCursor, RawBatchCommandCursor]],
|
future: "asyncio.Future[Union[CommandCursor, RawBatchCommandCursor]]",
|
||||||
) -> None:
|
) -> None:
|
||||||
try:
|
try:
|
||||||
self.dispatch = future.result()
|
self.dispatch = future.result()
|
||||||
@ -214,7 +217,9 @@ class AsyncLatentCommandCursor(AsyncCommandCursor):
|
|||||||
if original_future.done():
|
if original_future.done():
|
||||||
return
|
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.
|
# _get_more is complete.
|
||||||
original_future.set_result(
|
original_future.set_result(
|
||||||
len(self.dispatch._CommandCursor__data) # skipcq: PYL-W0212
|
len(self.dispatch._CommandCursor__data) # skipcq: PYL-W0212
|
||||||
@ -223,7 +228,7 @@ class AsyncLatentCommandCursor(AsyncCommandCursor):
|
|||||||
# Send a getMore.
|
# Send a getMore.
|
||||||
fut = self.loop.create_task(super()._get_more())
|
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():
|
if original_future.done():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -55,7 +55,9 @@ class AsyncCursorBase(AsyncBase, Generic[_DocumentType]):
|
|||||||
And we now have :meth:`~to_list()` so yeah kinda useless
|
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[
|
dispatch: Union[
|
||||||
"_LatentCursor[_DocumentType]",
|
"_LatentCursor[_DocumentType]",
|
||||||
"CommandCursor[_DocumentType]",
|
"CommandCursor[_DocumentType]",
|
||||||
@ -113,7 +115,8 @@ class AsyncCursorBase(AsyncBase, Generic[_DocumentType]):
|
|||||||
def _get_more(self) -> Coroutine[Any, Any, int]:
|
def _get_more(self) -> Coroutine[Any, Any, int]:
|
||||||
if not self.alive:
|
if not self.alive:
|
||||||
raise InvalidOperation(
|
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
|
self.started = True
|
||||||
@ -123,8 +126,8 @@ class AsyncCursorBase(AsyncBase, Generic[_DocumentType]):
|
|||||||
self,
|
self,
|
||||||
length: Optional[int],
|
length: Optional[int],
|
||||||
the_list: List[Mapping[str, Any]],
|
the_list: List[Mapping[str, Any]],
|
||||||
future: asyncio.Future[List[Mapping[str, Any]]],
|
future: "asyncio.Future[List[Mapping[str, Any]]]",
|
||||||
get_more_future: asyncio.Future[int],
|
get_more_future: "asyncio.Future[int]",
|
||||||
) -> None:
|
) -> None:
|
||||||
# get_more_future is the result of self._get_more().
|
# get_more_future is the result of self._get_more().
|
||||||
# future will be the result of the user's to_list() call.
|
# future will be the result of the user's to_list() call.
|
||||||
@ -150,7 +153,13 @@ class AsyncCursorBase(AsyncBase, Generic[_DocumentType]):
|
|||||||
else:
|
else:
|
||||||
new_future = self.loop.create_task(self._get_more())
|
new_future = self.loop.create_task(self._get_more())
|
||||||
new_future.add_done_callback(
|
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
|
except Exception as exc: # skipcq: PYL-W0703
|
||||||
if not future.done():
|
if not future.done():
|
||||||
@ -173,7 +182,9 @@ class AsyncCursorBase(AsyncBase, Generic[_DocumentType]):
|
|||||||
return await run_sync(next, self.dispatch)
|
return await run_sync(next, self.dispatch)
|
||||||
raise StopAsyncIteration
|
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:
|
if length is not None and length < 0:
|
||||||
raise ValueError("length must be non-negative")
|
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 = self.loop.create_task(get_more_future)
|
||||||
|
|
||||||
get_more_future.add_done_callback(
|
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
|
return future
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "async-pymongo"
|
name = "async-pymongo"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
description = "Asynchronous wrapper for pymongo"
|
description = "Asynchronous wrapper for pymongo"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
authors = [
|
authors = [
|
||||||
"Adek Maulana <adekzmaulana@gmail.com>",
|
"Adek Maulana <adekzmaulana@gmail.com>",
|
||||||
"Gaung Ramadhan <hi@mrmiss.my.id>",
|
"Gaung Ramadhan <hi@mrmiss.my.id>",
|
||||||
"wulan17 <wulan17@nusantararom.org>"
|
"wulan17 <wulan17@nusantararom.org>",
|
||||||
]
|
]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
repository = "https://github.com/Mayuri-Chan/async_pymongo"
|
repository = "https://github.com/Mayuri-Chan/async_pymongo"
|
||||||
@ -17,6 +17,7 @@ classifiers = [
|
|||||||
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
|
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
|
||||||
"Programming Language :: Python",
|
"Programming Language :: Python",
|
||||||
"Programming Language :: Python :: 3",
|
"Programming Language :: Python :: 3",
|
||||||
|
"Programming Language :: Python :: 3.8",
|
||||||
"Programming Language :: Python :: 3.9",
|
"Programming Language :: Python :: 3.9",
|
||||||
"Programming Language :: Python :: 3.10",
|
"Programming Language :: Python :: 3.10",
|
||||||
"Programming Language :: Python :: 3.11",
|
"Programming Language :: Python :: 3.11",
|
||||||
@ -24,10 +25,10 @@ classifiers = [
|
|||||||
"Topic :: Database",
|
"Topic :: Database",
|
||||||
]
|
]
|
||||||
|
|
||||||
packages = [{include = "async_pymongo"}]
|
packages = [{ include = "async_pymongo" }]
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "~=3.9"
|
python = "~=3.8"
|
||||||
pymongo = "^4.3.3"
|
pymongo = "^4.3.3"
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user