You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/examples/type_hints.rst
+9-6Lines changed: 9 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,9 +94,10 @@ Typed Collection
94
94
95
95
You can use :py:class:`~typing_extensions.TypedDict` (Python 3.8+) when using a well-defined schema for the data in a :class:`~pymongo.collection.Collection`.
96
96
Note that all `schema_validation`_ for inserts and updates is done on the server. This is due to the fact that these methods automatically add
97
-
an "_id" field. The "_id" field is decorated by :py:class:`~typing_extensions.NotRequired` decorator to allow it to be accessed when reading
98
-
from `result` (albeit without type-checking for that specific field, hence why it should not be used for schema validation).
99
-
Another option would be to generate the "_id" field yourself, and make it a required field, which would give the expected behavior.
97
+
an "_id" field. In the example below the "_id" field is marked by the :py:class:`~typing_extensions.NotRequired` notation to allow it to be accessed when reading
98
+
from `result`. If it is simply not included in the definition, then it will be automatically added, but it will raise a type-checking error if you attempt to access it.
99
+
Another option would be to generate the "_id" field yourself, and make it a required field. This would give the expected behavior, but would then also prevent you from
100
+
relying on PyMongo to insert the "_id" field.
100
101
101
102
.. doctest::
102
103
@@ -111,12 +112,14 @@ Another option would be to generate the "_id" field yourself, and make it a requ
0 commit comments