Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ lint-manual *args="": && resync

[group('test')]
test *args="-v --durations=5 --maxfail=10": && resync
uvx --extra test pytest {{args}}
uv run --extra test pytest {{args}}

[group('test')]
run-tests *args: && resync
Expand Down
2 changes: 1 addition & 1 deletion pymongo/asynchronous/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3143,7 +3143,7 @@ async def distinct(
comment: Optional[Any] = None,
hint: Optional[_IndexKeyHint] = None,
**kwargs: Any,
) -> list[str]:
) -> list[Any]:
"""Get a list of distinct values for `key` among all documents
in this collection.

Expand Down
2 changes: 1 addition & 1 deletion pymongo/asynchronous/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ async def close(self) -> None:
"""Explicitly close / kill this cursor."""
await self._die_lock()

async def distinct(self, key: str) -> list[str]:
async def distinct(self, key: str) -> list[Any]:
"""Get a list of distinct values for `key` among all documents
in the result set of this query.

Expand Down
2 changes: 1 addition & 1 deletion pymongo/synchronous/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3136,7 +3136,7 @@ def distinct(
comment: Optional[Any] = None,
hint: Optional[_IndexKeyHint] = None,
**kwargs: Any,
) -> list[str]:
) -> list[Any]:
"""Get a list of distinct values for `key` among all documents
in this collection.

Expand Down
2 changes: 1 addition & 1 deletion pymongo/synchronous/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ def close(self) -> None:
"""Explicitly close / kill this cursor."""
self._die_lock()

def distinct(self, key: str) -> list[str]:
def distinct(self, key: str) -> list[Any]:
"""Get a list of distinct values for `key` among all documents
in the result set of this query.

Expand Down
28 changes: 27 additions & 1 deletion test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ImplicitMovie(TypedDict):

from test import IntegrationTest, PyMongoTestCase, client_context

from bson import CodecOptions, decode, decode_all, decode_file_iter, decode_iter, encode
from bson import CodecOptions, ObjectId, decode, decode_all, decode_file_iter, decode_iter, encode
from bson.raw_bson import RawBSONDocument
from bson.son import SON
from pymongo import ASCENDING, MongoClient
Expand Down Expand Up @@ -141,6 +141,32 @@ def to_list(iterable: Iterable[Dict[str, Any]]) -> List[Dict[str, Any]]:
docs = to_list(cursor)
self.assertTrue(docs)

def test_district(self) -> None:
self.coll.delete_many({})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/test_district/test_distinct/ ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol yep

self.coll.insert_many(
[
{"_id": None},
{"_id": 0},
{"_id": ""},
{"_id": ObjectId()},
{"_id": True},
]
)

def collection_distinct(
collection: Collection,
) -> list[None | int | str | ObjectId | bool]:
return collection.distinct("_id")

def cursor_distinct(
collection: Collection,
) -> list[None | int | str | ObjectId | bool]:
cursor = collection.find()
return cursor.distinct("_id")

collection_distinct(self.coll)
cursor_distinct(self.coll)

@only_type_check
def test_bulk_write(self) -> None:
self.coll.insert_one({})
Expand Down
Loading