diff --git a/doc/changelog.rst b/doc/changelog.rst index 8b2d94becd..2a99b1a701 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -22,10 +22,16 @@ Bug fixes from it. It now raises :class:`~bson.errors.InvalidId`, and :meth:`~bson.objectid.ObjectId.is_valid` returns ``False`` for such a string (`PYTHON-5873`_). +- Fixed the type annotation of the ``let`` argument of + :class:`~pymongo.cursor.Cursor` and + :class:`~pymongo.asynchronous.cursor.AsyncCursor`. It is now + ``Optional[Mapping[str, Any]]`` instead of ``Optional[bool]``, matching what + the argument accepts at runtime (`PYTHON-6145`_). .. _PYTHON-6172: https://jira.mongodb.org/browse/PYTHON-6172 .. _PYTHON-6149: https://jira.mongodb.org/browse/PYTHON-6149 .. _PYTHON-5873: https://jira.mongodb.org/browse/PYTHON-5873 +.. _PYTHON-6145: https://jira.mongodb.org/browse/PYTHON-6145 Changes in Version 4.19.0 (2026/10/14) -------------------------------------- diff --git a/pymongo/cursor_shared.py b/pymongo/cursor_shared.py index 2b62b11f04..3a0acbe932 100644 --- a/pymongo/cursor_shared.py +++ b/pymongo/cursor_shared.py @@ -396,7 +396,7 @@ def __init__( comment: Optional[Any] = None, session: Optional[_AgnosticClientSession] = None, allow_disk_use: Optional[bool] = None, - let: Optional[bool] = None, + let: Optional[Mapping[str, Any]] = None, ) -> None: """Create a new cursor. Used by a collection's ``find()`` method to iterate over MongoDB query results. diff --git a/test/test_typing.py b/test/test_typing.py index 24ef06755f..054466e729 100644 --- a/test/test_typing.py +++ b/test/test_typing.py @@ -71,6 +71,7 @@ class ImplicitMovie(TypedDict): from pymongo.operations import DeleteOne, InsertOne, ReplaceOne from pymongo.read_preferences import ReadPreference from pymongo.synchronous.collection import Collection +from pymongo.synchronous.cursor import Cursor from test import IntegrationTest, PyMongoTestCase, client_context TEST_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "mypy_fails") @@ -137,6 +138,10 @@ def to_list(iterable: Iterable[dict[str, Any]]) -> list[dict[str, Any]]: docs = to_list(cursor) self.assertTrue(docs) + @only_type_check + def test_cursor_let(self) -> None: + Cursor(self.coll, let={"threshold": 1}) + def test_distinct(self) -> None: self.coll.delete_many({}) self.coll.insert_many(