@@ -92,12 +92,13 @@ Note that when using :class:`~bson.son.SON`, the key and value types must be giv
92
92
Typed Collection
93
93
----------------
94
94
95
- You can use :py:class: `~typing.TypedDict ` when using a well-defined schema for the data in a :class: `~pymongo.collection.Collection `:
95
+ You can use :py:class: `~typing.TypedDict ` (Python 3.8+) when using a well-defined schema for the data in a :class: `~pymongo.collection.Collection `:
96
96
97
97
.. doctest ::
98
98
99
99
>>> from typing import TypedDict
100
- >>> from pymongo import MongoClient, Collection
100
+ >>> from pymongo import MongoClient
101
+ >>> from pymongo.collection import Collection
101
102
>>> class Movie (TypedDict ):
102
103
... name: str
103
104
... year: int
@@ -113,13 +114,14 @@ Typed Database
113
114
--------------
114
115
115
116
While less common, you could specify that the documents in an entire database
116
- match a well-defined shema using :py:class: `~typing.TypedDict `.
117
+ match a well-defined shema using :py:class: `~typing.TypedDict ` (Python 3.8+) .
117
118
118
119
119
120
.. doctest ::
120
121
121
122
>>> from typing import TypedDict
122
- >>> from pymongo import MongoClient, Database
123
+ >>> from pymongo import MongoClient
124
+ >>> from pymongo.database import Database
123
125
>>> class Movie (TypedDict ):
124
126
... name: str
125
127
... year: int
@@ -146,7 +148,7 @@ When using the :meth:`~pymongo.database.Database.command`, you can specify the d
146
148
>>> result = client.admin.command(" ping" , codec_options = options)
147
149
>>> assert isinstance (result, RawBSONDocument)
148
150
149
- Custom :py:class: `collections.abc.Mapping ` subclasses and :py:class: `~typing.TypedDict ` are also supported.
151
+ Custom :py:class: `collections.abc.Mapping ` subclasses and :py:class: `~typing.TypedDict ` (Python 3.8+) are also supported.
150
152
For :py:class: `~typing.TypedDict `, use the form: ``options: CodecOptions[MyTypedDict] = CodecOptions(...) ``.
151
153
152
154
Typed BSON Decoding
@@ -167,7 +169,7 @@ You can specify the document type returned by :mod:`bson` decoding functions by
167
169
>>> rt_document = decode(bsonbytes, codec_options = options)
168
170
>>> assert rt_document.foo() == " bar"
169
171
170
- :class: `~bson.raw_bson.RawBSONDocument ` and :py:class: `~typing.TypedDict ` are also supported.
172
+ :class: `~bson.raw_bson.RawBSONDocument ` and :py:class: `~typing.TypedDict ` (Python 3.8+) are also supported.
171
173
For :py:class: `~typing.TypedDict `, use the form: ``options: CodecOptions[MyTypedDict] = CodecOptions(...) ``.
172
174
173
175
0 commit comments