Skip to content

Commit a3d983c

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver
2 parents c096fc9 + 5a0c81c commit a3d983c

File tree

10 files changed

+81
-31
lines changed

10 files changed

+81
-31
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Global owner for repo
2+
* @mongodb/dbx-python

.github/workflows/release-python.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88
- "[0-9]+.[0-9]+.[0-9]+[a-b][0-9]+"
99
- "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
1010
workflow_dispatch:
11-
pull_request:
1211

1312
concurrency:
1413
group: wheels-${{ github.ref }}

.github/workflows/test-python.yml

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ defaults:
1515

1616
jobs:
1717

18-
lint:
18+
static:
1919
runs-on: ubuntu-latest
2020
steps:
2121
- uses: actions/checkout@v4
2222
- uses: actions/setup-python@v5
2323
with:
24-
python-version: 3.8
24+
python-version: "3.8"
2525
cache: 'pip'
2626
cache-dependency-path: 'pyproject.toml'
2727
- name: Install Python dependencies
@@ -30,7 +30,21 @@ jobs:
3030
- name: Run linters
3131
run: |
3232
tox -m lint-manual
33+
- name: Check Manifest
34+
run: |
3335
tox -m manifest
36+
- name: Run compilation
37+
run: |
38+
pip install -e .
39+
python tools/fail_if_no_c.py
40+
- name: Run typecheck
41+
run: |
42+
tox -m typecheck
43+
- run: |
44+
sudo apt-get install -y cppcheck
45+
- run: |
46+
cppcheck --force bson
47+
cppcheck pymongo
3448
3549
build:
3650
# supercharge/mongodb-github-action requires containers so we don't test other platforms
@@ -81,28 +95,29 @@ jobs:
8195
run: |
8296
tox -m doc-test
8397
84-
typing:
85-
name: Typing Tests
98+
docs:
99+
name: Docs Checks
86100
runs-on: ubuntu-latest
87-
strategy:
88-
matrix:
89-
python: ["3.7", "3.11"]
90101
steps:
91102
- uses: actions/checkout@v4
92103
- uses: actions/setup-python@v5
93104
with:
94-
python-version: "${{matrix.python}}"
95105
cache: 'pip'
96106
cache-dependency-path: 'pyproject.toml'
107+
# Build docs on lowest supported Python for furo
108+
python-version: '3.8'
97109
- name: Install dependencies
98110
run: |
99111
pip install -q tox
100-
- name: Run typecheck
112+
- name: Check links
101113
run: |
102-
tox -m typecheck
114+
tox -m linkcheck
115+
- name: Build docs
116+
run: |
117+
tox -m doc
103118
104-
docs:
105-
name: Docs Checks
119+
linkcheck:
120+
name: Link Check
106121
runs-on: ubuntu-latest
107122
steps:
108123
- uses: actions/checkout@v4
@@ -115,12 +130,29 @@ jobs:
115130
- name: Install dependencies
116131
run: |
117132
pip install -q tox
118-
- name: Check links
133+
- name: Build docs
119134
run: |
120135
tox -m linkcheck
121-
- name: Build docs
136+
137+
typing:
138+
name: Typing Tests
139+
runs-on: ubuntu-latest
140+
strategy:
141+
matrix:
142+
python: ["3.7", "3.11"]
143+
steps:
144+
- uses: actions/checkout@v4
145+
- uses: actions/setup-python@v5
146+
with:
147+
python-version: "${{matrix.python}}"
148+
cache: 'pip'
149+
cache-dependency-path: 'pyproject.toml'
150+
- name: Install dependencies
122151
run: |
123-
tox -m doc
152+
pip install -q tox
153+
- name: Run typecheck
154+
run: |
155+
tox -m typecheck
124156
125157
make_sdist:
126158
runs-on: ubuntu-latest

bson/datetime_ms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, value: Union[int, datetime.datetime]):
5151
encoding/decoding BSON.
5252
5353
To decode UTC datetimes as a ``DatetimeMS``, `datetime_conversion` in
54-
:class:`~bson.CodecOptions` must be set to 'datetime_ms' or
54+
:class:`~bson.codec_options.CodecOptions` must be set to 'datetime_ms' or
5555
'datetime_auto'. See :ref:`handling-out-of-range-datetimes` for
5656
details.
5757

doc/migrate-to-pymongo4.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@ Removed :meth:`pymongo.database.Database.collection_names`. Use
328328
:meth:`~pymongo.database.Database.list_collection_names` instead. Code like
329329
this::
330330

331-
names = client.collection_names()
332-
non_system_names = client.collection_names(include_system_collections=False)
331+
names = client.db.collection_names()
332+
non_system_names = client.db.collection_names(include_system_collections=False)
333333

334334
can be changed to this::
335335

336-
names = client.list_collection_names()
337-
non_system_names = client.list_collection_names(filter={"name": {"$regex": r"^(?!system\\.)"}})
336+
names = client.db.list_collection_names()
337+
non_system_names = client.db.list_collection_names(filter={"name": {"$regex": "^(?!system\\.)"}})
338338

339339
Database.current_op is removed
340340
..............................

gridfs/grid_file.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io
2020
import math
2121
import os
22+
import warnings
2223
from typing import Any, Iterable, Mapping, NoReturn, Optional
2324

2425
from bson.int64 import Int64
@@ -69,8 +70,15 @@ def _grid_in_property(
6970
closed_only: Optional[bool] = False,
7071
) -> Any:
7172
"""Create a GridIn property."""
73+
warn_str = ""
74+
if docstring.startswith("DEPRECATED,"):
75+
warn_str = (
76+
f"GridIn property '{field_name}' is deprecated and will be removed in PyMongo 5.0"
77+
)
7278

7379
def getter(self: Any) -> Any:
80+
if warn_str:
81+
warnings.warn(warn_str, stacklevel=2, category=DeprecationWarning)
7482
if closed_only and not self._closed:
7583
raise AttributeError("can only get %r on a closed file" % field_name)
7684
# Protect against PHP-237
@@ -79,6 +87,8 @@ def getter(self: Any) -> Any:
7987
return self._file.get(field_name, None)
8088

8189
def setter(self: Any, value: Any) -> Any:
90+
if warn_str:
91+
warnings.warn(warn_str, stacklevel=2, category=DeprecationWarning)
8292
if self._closed:
8393
self._coll.files.update_one({"_id": self._file["_id"]}, {"$set": {field_name: value}})
8494
self._file[field_name] = value
@@ -100,8 +110,15 @@ def setter(self: Any, value: Any) -> Any:
100110

101111
def _grid_out_property(field_name: str, docstring: str) -> Any:
102112
"""Create a GridOut property."""
113+
warn_str = ""
114+
if docstring.startswith("DEPRECATED,"):
115+
warn_str = (
116+
f"GridOut property '{field_name}' is deprecated and will be removed in PyMongo 5.0"
117+
)
103118

104119
def getter(self: Any) -> Any:
120+
if warn_str:
121+
warnings.warn(warn_str, stacklevel=2, category=DeprecationWarning)
105122
self._ensure_file()
106123

107124
# Protect against PHP-237

pymongo/collection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ class ReturnDocument:
114114

115115

116116
if TYPE_CHECKING:
117-
import bson
118117
from pymongo.aggregation import _AggregationCommand
119118
from pymongo.client_session import ClientSession
120119
from pymongo.collation import Collation
@@ -420,7 +419,7 @@ def database(self) -> Database[_DocumentType]:
420419

421420
def with_options(
422421
self,
423-
codec_options: Optional[bson.CodecOptions[_DocumentTypeArg]] = None,
422+
codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None,
424423
read_preference: Optional[_ServerMode] = None,
425424
write_concern: Optional[WriteConcern] = None,
426425
read_concern: Optional[ReadConcern] = None,

pymongo/database.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(
7676
self,
7777
client: MongoClient[_DocumentType],
7878
name: str,
79-
codec_options: Optional[bson.CodecOptions[_DocumentTypeArg]] = None,
79+
codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None,
8080
read_preference: Optional[_ServerMode] = None,
8181
write_concern: Optional[WriteConcern] = None,
8282
read_concern: Optional[ReadConcern] = None,
@@ -154,7 +154,7 @@ def name(self) -> str:
154154

155155
def with_options(
156156
self,
157-
codec_options: Optional[bson.CodecOptions[_DocumentTypeArg]] = None,
157+
codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None,
158158
read_preference: Optional[_ServerMode] = None,
159159
write_concern: Optional[WriteConcern] = None,
160160
read_concern: Optional[ReadConcern] = None,
@@ -238,7 +238,7 @@ def __getitem__(self, name: str) -> Collection[_DocumentType]:
238238
def get_collection(
239239
self,
240240
name: str,
241-
codec_options: Optional[bson.CodecOptions[_DocumentTypeArg]] = None,
241+
codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None,
242242
read_preference: Optional[_ServerMode] = None,
243243
write_concern: Optional[WriteConcern] = None,
244244
read_concern: Optional[ReadConcern] = None,
@@ -320,7 +320,7 @@ def _get_encrypted_fields(
320320
def create_collection(
321321
self,
322322
name: str,
323-
codec_options: Optional[bson.CodecOptions[_DocumentTypeArg]] = None,
323+
codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None,
324324
read_preference: Optional[_ServerMode] = None,
325325
write_concern: Optional[WriteConcern] = None,
326326
read_concern: Optional[ReadConcern] = None,

pymongo/mongo_client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555
cast,
5656
)
5757

58-
import bson
59-
from bson.codec_options import DEFAULT_CODEC_OPTIONS, TypeRegistry
58+
from bson.codec_options import DEFAULT_CODEC_OPTIONS, CodecOptions, TypeRegistry
6059
from bson.timestamp import Timestamp
6160
from pymongo import (
6261
_csot,
@@ -2032,7 +2031,7 @@ def drop_database(
20322031
def get_default_database(
20332032
self,
20342033
default: Optional[str] = None,
2035-
codec_options: Optional[bson.CodecOptions[_DocumentTypeArg]] = None,
2034+
codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None,
20362035
read_preference: Optional[_ServerMode] = None,
20372036
write_concern: Optional[WriteConcern] = None,
20382037
read_concern: Optional[ReadConcern] = None,
@@ -2092,7 +2091,7 @@ def get_default_database(
20922091
def get_database(
20932092
self,
20942093
name: Optional[str] = None,
2095-
codec_options: Optional[bson.CodecOptions[_DocumentTypeArg]] = None,
2094+
codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None,
20962095
read_preference: Optional[_ServerMode] = None,
20972096
write_concern: Optional[WriteConcern] = None,
20982097
read_concern: Optional[ReadConcern] = None,

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ filterwarnings = [
115115
"module:Unsupported compressor:UserWarning",
116116
"module:zlibcompressionlevel must be:UserWarning",
117117
"module:Wire protocol compression with:UserWarning",
118+
"module:GridIn property:DeprecationWarning",
119+
"module:GridOut property:DeprecationWarning",
118120
# TODO: Remove as part of PYTHON-3923.
119121
"module:unclosed <eventlet.green.ssl.GreenSSLSocket:ResourceWarning",
120122
"module:unclosed <socket.socket:ResourceWarning",

0 commit comments

Comments
 (0)