Skip to content

Commit c420d12

Browse files
committed
rm feedback
1 parent 4a208ee commit c420d12

File tree

9 files changed

+31
-35
lines changed

9 files changed

+31
-35
lines changed

source/connect/mongoclient.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ constructor accepts. All parameters are optional.
137137
- ``bson.raw_bson.RawBSONDocument``.
138138
- A subclass of the ``collections.abc.Mapping`` type, such as ``bson.son.SON``.
139139
If you specify ``bson.son.SON`` as the document class, you must also specify types
140-
for the key and value.
140+
for the key and value, as shown in the following example:
141+
142+
.. code-block:: python
143+
144+
client = MongoClient(document_class=SON[str, int])
145+
141146
- A subclass of the ``TypedDict`` type. To pass a ``TypedDict`` subclass for this
142147
parameter, you must also include the class in a type hint for your ``MongoClient``
143148
object, as shown in the following example:
@@ -149,6 +154,7 @@ constructor accepts. All parameters are optional.
149154
.. include:: /includes/type-hints/typeddict-availability.rst
150155

151156
**Data type:** ``Type[_DocumentType]``
157+
**Default:** ``dict``
152158

153159
* - ``tz_aware``
154160
- If this parameter is ``True``, the client treats ``datetime`` values as aware.

source/includes/type-hints/intro.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
If your application uses Python 3.5 or later, you can add *type hints*,
22
as described in `PEP 484 <https://peps.python.org/pep-0484/>`__, to your code.
33
Type hints denote the data types of variables, parameters, and function return
4-
values, as well as the structure of documents.
4+
values, and the structure of documents.
55
Some IDEs can use type hints to check your code for type errors and suggest
66
appropriate options for code completion.

source/includes/type-hints/tip-more-info.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.. tip:: Type-Checking Tools
2+
3+
To learn more about type-checking tools available for Python, see
4+
:ref:`Type Checkers <pymongo-tools-type-checkers>` on the Tools page.

source/includes/type-hints/troubleshooting-incompatible-type.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
Incompatible Type
22
~~~~~~~~~~~~~~~~~
33

4-
If you use the generic form of the ``MongoClient`` class, your type checker might
5-
show an error similar to the following:
4+
If you specify ``MongoClient`` as a type hint but don't include data types for
5+
the document, keys, and values, your type checker might show an error similar to
6+
the following:
67

78
.. code-block:: python
89
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
The ``TypedDict`` class is in the ``typing`` module, which
1+
The `TypedDict <https://docs.python.org/3/library/typing.html#typing.TypedDict>`__ class
2+
is in the ``typing`` module, which
23
is available only in Python 3.8 and later. To use the ``TypedDict`` class in
3-
earlier versions of Python, install the ``typing_extensions`` package.
4+
earlier versions of Python, install the
5+
`typing_extensions <https://pypi.org/project/typing-extensions/>`__ package.

source/read/retrieve.txt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -199,24 +199,6 @@ to the ``find()`` method:
199199

200200
.. include:: /includes/collation-override-note.rst
201201

202-
Troubleshooting
203-
---------------
204-
205-
Modifying Raw BSON
206-
~~~~~~~~~~~~~~~~~~
207-
208-
Instances of the ``RawBSONDocument`` class are read-only. If you try to set a value on a
209-
``RawBSONDocument`` object, you will see an error similar to one of the following:
210-
211-
.. code-block:: python
212-
213-
error: Unsupported target for indexed assignment
214-
("RawBSONDocument") [index]
215-
216-
.. code-block:: python
217-
218-
TypeError: 'RawBSONDocument' object does not support item assignment
219-
220202
.. _pymongo-retrieve-additional-information:
221203

222204
Additional Information

source/write/bulk-write.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ class for added type safety:
193193

194194
To replace multiple documents, you must create an instance of ``ReplaceOne`` for each document.
195195

196+
.. include:: /includes/type-hints/tip-type-checkers.rst
197+
196198
Delete Operations
197199
~~~~~~~~~~~~~~~~~
198200

source/write/insert.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ method for added type safety:
7777
class Restaurant(TypedDict):
7878
name: str
7979

80-
sample_restaurants.restaurants.insert_one(Movie(name="Mongo's Burgers")
80+
sample_restaurants.restaurants.insert_one(Restaurant(name="Mongo's Burgers")
81+
82+
.. include:: /includes/type-hints/tip-type-checkers.rst
8183

8284
Insert Multiple Documents
8385
-------------------------
@@ -121,6 +123,8 @@ instances of the ``Restaurant`` class. This adds type safety to the insert opera
121123

122124
sample_restaurants.restaurants.insert_many(document_list)
123125

126+
.. include:: /includes/type-hints/tip-type-checkers.rst
127+
124128
Modify Insert Behavior
125129
----------------------
126130

@@ -205,7 +209,7 @@ calling the ``insert_many()`` method instead.
205209
TypedDict Missing _id Key
206210
~~~~~~~~~~~~~~~~~~~~~~~~~
207211

208-
As discussed above, if you don't specify the ``_id`` field, {+driver-short+} automatically
212+
If you don't specify the ``_id`` field, {+driver-short+} automatically
209213
inserts it into the document.
210214
You can retrieve the value of the ``_id`` field at runtime, but if you use MyPy or another
211215
tool to perform static type-checking, it won't find the ``_id`` field in your class and
@@ -313,8 +317,10 @@ The following code example shows how to implement this solution:
313317

314318
.. important:: NotRequired Requires Python 3.11+
315319

316-
The ``NotRequired`` class is available only in Python 3.11 and later.
317-
To use ``NotRequired`` in earlier versions of Python, install the ``typing_extensions``
320+
The `NotRequired <https://docs.python.org/3/library/typing.html#typing.NotRequired>`__
321+
class is available only in Python 3.11 and later.
322+
To use ``NotRequired`` in earlier versions of Python, install the
323+
`typing_extensions <https://pypi.org/project/typing-extensions/>`__
318324
package instead.
319325

320326
Additional Information

0 commit comments

Comments
 (0)