Skip to content

Commit 0eae39a

Browse files
committed
rm feedback
1 parent f99dfb7 commit 0eae39a

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
@@ -158,6 +158,8 @@ class for added type safety:
158158

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

161+
.. include:: /includes/type-hints/tip-type-checkers.rst
162+
161163
Delete Operations
162164
~~~~~~~~~~~~~~~~~
163165

source/write/insert.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ method for added type safety:
105105
class Restaurant(TypedDict):
106106
name: str
107107

108-
sample_restaurants.restaurants.insert_one(Movie(name="Mongo's Burgers")
108+
sample_restaurants.restaurants.insert_one(Restaurant(name="Mongo's Burgers")
109+
110+
.. include:: /includes/type-hints/tip-type-checkers.rst
109111

110112
Insert Multiple Documents
111113
-------------------------
@@ -149,6 +151,8 @@ instances of the ``Restaurant`` class. This adds type safety to the insert opera
149151

150152
sample_restaurants.restaurants.insert_many(document_list)
151153

154+
.. include:: /includes/type-hints/tip-type-checkers.rst
155+
152156
Modify Insert Behavior
153157
----------------------
154158

@@ -233,7 +237,7 @@ calling the ``insert_many()`` method instead.
233237
TypedDict Missing _id Key
234238
~~~~~~~~~~~~~~~~~~~~~~~~~
235239

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

342346
.. important:: NotRequired Requires Python 3.11+
343347

344-
The ``NotRequired`` class is available only in Python 3.11 and later.
345-
To use ``NotRequired`` in earlier versions of Python, install the ``typing_extensions``
348+
The `NotRequired <https://docs.python.org/3/library/typing.html#typing.NotRequired>`__
349+
class is available only in Python 3.11 and later.
350+
To use ``NotRequired`` in earlier versions of Python, install the
351+
`typing_extensions <https://pypi.org/project/typing-extensions/>`__
346352
package instead.
347353

348354
Additional Information

0 commit comments

Comments
 (0)