Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ repos:
name: ruff-format
entry: uv run --group lint ruff format
language: system
types_or: [python, pyi]
types_or: [python, pyi, markdown]
require_serial: true

- repo: local
Expand Down
2 changes: 1 addition & 1 deletion CODING-STANDARDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ if result == ...
from pymongo import MongoClient

if TYPE_CHECKING:
from pymongo.collection import Collection
from pymongo.collection import Collection

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change is hilariously ironic. 😂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nods 😂

```

# Backwards compatibility
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,13 @@ ObjectId('4aba160ee23f6b543e000002')
{'x': 10, '_id': ObjectId('4aba15ebe23f6b53b0000000')}
>>> for item in db.my_collection.find():
... print(item["x"])
...
10
8
11
>>> db.my_collection.create_index("x")
'x_1'
>>> for item in db.my_collection.find().sort("x", pymongo.ASCENDING):
... print(item["x"])
...
8
10
11
Expand Down
2 changes: 1 addition & 1 deletion bson/decimal128.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class DecimalEncoder(TypeEncoder):
For example::
opts = CodecOptions(type_registry=TypeRegistry([DecimalEncoder()]))
bson.encode({"d": decimal.Decimal('1.0')}, codec_options=opts)
bson.encode({"d": decimal.Decimal("1.0")}, codec_options=opts)
.. versionadded:: 4.15
"""
Expand Down
1 change: 0 additions & 1 deletion bson/raw_bson.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
... print(f"raw document: {doc.raw}")
... print(f"decoded document: {bson.decode(doc.raw)}")
... result = replica_db.test.insert_one(doc)
...
raw document: b'...'
decoded document: {'_id': 1, 'a': 1}
raw document: b'...'
Expand Down
26 changes: 12 additions & 14 deletions gridfs/asynchronous/grid_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ def find(self, *args: Any, **kwargs: Any) -> AsyncGridOutCursor:
arbitrary queries on the files collection. Can be combined
with other modifiers for additional control. For example::
for grid_out in fs.find({"filename": "lisa.txt"},
no_cursor_timeout=True):
for grid_out in fs.find({"filename": "lisa.txt"}, no_cursor_timeout=True):
data = grid_out.read()
would iterate through all versions of "lisa.txt" stored in GridFS.
Expand Down Expand Up @@ -548,8 +547,8 @@ def open_upload_stream(
my_db = MongoClient().test
fs = GridFSBucket(my_db)
with fs.open_upload_stream(
"test_file", chunk_size_bytes=4,
metadata={"contentType": "text/plain"}) as grid_in:
"test_file", chunk_size_bytes=4, metadata={"contentType": "text/plain"}
) as grid_in:
grid_in.write("data I want to store!")
# uploaded on close
Expand Down Expand Up @@ -602,10 +601,8 @@ def open_upload_stream_with_id(
my_db = MongoClient().test
fs = GridFSBucket(my_db)
with fs.open_upload_stream_with_id(
ObjectId(),
"test_file",
chunk_size_bytes=4,
metadata={"contentType": "text/plain"}) as grid_in:
ObjectId(), "test_file", chunk_size_bytes=4, metadata={"contentType": "text/plain"}
) as grid_in:
grid_in.write("data I want to store!")
# uploaded on close
Expand Down Expand Up @@ -664,7 +661,8 @@ async def upload_from_stream(
"test_file",
"data I want to store!",
chunk_size_bytes=4,
metadata={"contentType": "text/plain"})
metadata={"contentType": "text/plain"},
)
Returns the _id of the uploaded file.
Expand Down Expand Up @@ -716,7 +714,8 @@ async def upload_from_stream_with_id(
"test_file",
"data I want to store!",
chunk_size_bytes=4,
metadata={"contentType": "text/plain"})
metadata={"contentType": "text/plain"},
)
Raises :exc:`~gridfs.errors.NoFile` if no such version of
that file exists.
Expand Down Expand Up @@ -787,7 +786,7 @@ async def download_to_stream(
# Get _id of file to read
file_id = fs.upload_from_stream("test_file", "data I want to store!")
# Get file to write to
file = open('myfile','wb+')
file = open("myfile", "wb+")
fs.download_to_stream(file_id, file)
file.seek(0)
contents = file.read()
Expand Down Expand Up @@ -877,8 +876,7 @@ def find(self, *args: Any, **kwargs: Any) -> AsyncGridOutCursor:
For example::
for grid_data in fs.find({"filename": "lisa.txt"},
no_cursor_timeout=True):
for grid_data in fs.find({"filename": "lisa.txt"}, no_cursor_timeout=True):
data = grid_data.read()
would iterate through all versions of "lisa.txt" stored in GridFS.
Expand Down Expand Up @@ -983,7 +981,7 @@ async def download_to_stream_by_name(
my_db = MongoClient().test
fs = GridFSBucket(my_db)
# Get file to write to
file = open('myfile','wb')
file = open("myfile", "wb")
fs.download_to_stream_by_name("test_file", file)
Raises :exc:`~gridfs.errors.NoFile` if no such version of
Expand Down
26 changes: 12 additions & 14 deletions gridfs/synchronous/grid_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,7 @@ def find(self, *args: Any, **kwargs: Any) -> GridOutCursor:
arbitrary queries on the files collection. Can be combined
with other modifiers for additional control. For example::
for grid_out in fs.find({"filename": "lisa.txt"},
no_cursor_timeout=True):
for grid_out in fs.find({"filename": "lisa.txt"}, no_cursor_timeout=True):
data = grid_out.read()
would iterate through all versions of "lisa.txt" stored in GridFS.
Expand Down Expand Up @@ -546,8 +545,8 @@ def open_upload_stream(
my_db = MongoClient().test
fs = GridFSBucket(my_db)
with fs.open_upload_stream(
"test_file", chunk_size_bytes=4,
metadata={"contentType": "text/plain"}) as grid_in:
"test_file", chunk_size_bytes=4, metadata={"contentType": "text/plain"}
) as grid_in:
grid_in.write("data I want to store!")
# uploaded on close
Expand Down Expand Up @@ -600,10 +599,8 @@ def open_upload_stream_with_id(
my_db = MongoClient().test
fs = GridFSBucket(my_db)
with fs.open_upload_stream_with_id(
ObjectId(),
"test_file",
chunk_size_bytes=4,
metadata={"contentType": "text/plain"}) as grid_in:
ObjectId(), "test_file", chunk_size_bytes=4, metadata={"contentType": "text/plain"}
) as grid_in:
grid_in.write("data I want to store!")
# uploaded on close
Expand Down Expand Up @@ -662,7 +659,8 @@ def upload_from_stream(
"test_file",
"data I want to store!",
chunk_size_bytes=4,
metadata={"contentType": "text/plain"})
metadata={"contentType": "text/plain"},
)
Returns the _id of the uploaded file.
Expand Down Expand Up @@ -712,7 +710,8 @@ def upload_from_stream_with_id(
"test_file",
"data I want to store!",
chunk_size_bytes=4,
metadata={"contentType": "text/plain"})
metadata={"contentType": "text/plain"},
)
Raises :exc:`~gridfs.errors.NoFile` if no such version of
that file exists.
Expand Down Expand Up @@ -781,7 +780,7 @@ def download_to_stream(
# Get _id of file to read
file_id = fs.upload_from_stream("test_file", "data I want to store!")
# Get file to write to
file = open('myfile','wb+')
file = open("myfile", "wb+")
fs.download_to_stream(file_id, file)
file.seek(0)
contents = file.read()
Expand Down Expand Up @@ -869,8 +868,7 @@ def find(self, *args: Any, **kwargs: Any) -> GridOutCursor:
For example::
for grid_data in fs.find({"filename": "lisa.txt"},
no_cursor_timeout=True):
for grid_data in fs.find({"filename": "lisa.txt"}, no_cursor_timeout=True):
data = grid_data.read()
would iterate through all versions of "lisa.txt" stored in GridFS.
Expand Down Expand Up @@ -975,7 +973,7 @@ def download_to_stream_by_name(
my_db = MongoClient().test
fs = GridFSBucket(my_db)
# Get file to write to
file = open('myfile','wb')
file = open("myfile", "wb")
fs.download_to_stream_by_name("test_file", file)
Raises :exc:`~gridfs.errors.NoFile` if no such version of
Expand Down
2 changes: 1 addition & 1 deletion pymongo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def timeout(seconds: float | None) -> AbstractContextManager[None]:
with pymongo.timeout(5):
coll.find_one() # Uses the 5 second deadline.
with pymongo.timeout(3):
coll.find_one() # Uses the 3 second deadline.
coll.find_one() # Uses the 3 second deadline.
coll.find_one() # Uses the original 5 second deadline.
with pymongo.timeout(10):
coll.find_one() # Still uses the original 5 second deadline.
Expand Down
7 changes: 4 additions & 3 deletions pymongo/asynchronous/change_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async def next(self) -> _DocumentType:
try:
resume_token = None
pipeline = [{'$match': {'operationType': 'insert'}}]
pipeline = [{"$match": {"operationType": "insert"}}]
async with await db.collection.watch(pipeline) as stream:
async for insert_change in stream:
print(insert_change)
Expand All @@ -129,13 +129,14 @@ async def next(self) -> _DocumentType:
if resume_token is None:
# There is no usable resume token because there was a
# failure during AsyncChangeStream initialization.
logging.error('...')
logging.error("...")
else:
# Use the interrupted AsyncChangeStream's resume token to create
# a new AsyncChangeStream. The new stream will continue from the
# last seen insert change without missing any events.
async with await db.collection.watch(
pipeline, resume_after=resume_token) as stream:
pipeline, resume_after=resume_token
) as stream:
async for insert_change in stream:
print(insert_change)
Expand Down
6 changes: 4 additions & 2 deletions pymongo/asynchronous/client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,10 @@ async def callback(session):
orders = session.client.db.orders
inventory = session.client.db.inventory
await orders.insert_one({"sku": "abc123", "qty": 100}, session=session)
await inventory.update_one({"sku": "abc123", "qty": {"$gte": 100}},
{"$inc": {"qty": -100}}, session=session)
await inventory.update_one(
{"sku": "abc123", "qty": {"$gte": 100}}, {"$inc": {"qty": -100}}, session=session
)
async with client.start_session() as session:
await session.with_transaction(callback)
Expand Down
Loading
Loading