Skip to content

Commit

Permalink
MOTOR-1183 Typing issue in core.pyi causing MyPy error for to_list … (#…
Browse files Browse the repository at this point in the history
…226)

Co-authored-by: Sergi Pous <spous@objectvideo.com>
Co-authored-by: Steven Silvester <steven.silvester@ieee.org>
  • Loading branch information
3 people committed Aug 31, 2023
1 parent 5348e5a commit 62cf174
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
5 changes: 3 additions & 2 deletions motor/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from __future__ import annotations

from asyncio import Future
from typing import (
Any,
Awaitable,
Expand Down Expand Up @@ -654,11 +655,11 @@ class AgnosticBaseCursor(AgnosticBase):
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> Any: ...
def _get_more(self) -> int: ...
@property
def fetch_next(self) -> Any: ...
def fetch_next(self) -> Future[Any]: ...
def next_object(self) -> Any: ...
def each(self, callback: Callable) -> None: ...
def _each_got_more(self, callback: Callable, future: Any) -> None: ...
def to_list(self, length: int) -> List: ...
def to_list(self, length: int) -> Future[List]: ...
def _to_list(self, length: int, the_list: List, future: Any, get_more_result: Any) -> None: ...
def get_io_loop(self) -> Any: ...
def batch_size(self, batch_size: int) -> AgnosticBaseCursor: ...
Expand Down
9 changes: 3 additions & 6 deletions test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""
import unittest
from test.asyncio_tests import AsyncIOTestCase, asyncio_test
from typing import TYPE_CHECKING, Any, AsyncIterable, Dict, List, Union
from typing import TYPE_CHECKING, Any, Dict, List, Union

from bson import CodecOptions
from bson.raw_bson import RawBSONDocument
Expand Down Expand Up @@ -80,13 +80,10 @@ async def test_insert_find(self) -> None:
self.assertEqual(result2.inserted_id, result.inserted_id)

@asyncio_test
async def test_cursor_iterable(self) -> None:
async def to_list(iterable: AsyncIterable[Dict[str, Any]]) -> List[Dict[str, Any]]:
return [gen async for gen in iterable]

async def test_cursor_to_list(self) -> None:
await self.collection.insert_one({})
cursor = self.collection.find()
docs = await to_list(cursor)
docs = await cursor.to_list(None)
self.assertTrue(docs)

@only_type_check
Expand Down

0 comments on commit 62cf174

Please sign in to comment.