1717
1818from google .cloud .firestore_v1 import _helpers
1919from google .cloud .firestore_v1 .document import DocumentReference
20- from typing import Any , NoReturn , Tuple
21-
20+ from typing import (
21+ Any ,
22+ AsyncGenerator ,
23+ Coroutine ,
24+ Generator ,
25+ AsyncIterator ,
26+ Iterator ,
27+ NoReturn ,
28+ Tuple ,
29+ Union ,
30+ )
31+
32+ # Types needed only for Type Hints
33+ from google .cloud .firestore_v1 .base_document import DocumentSnapshot
34+ from google .cloud .firestore_v1 .base_query import BaseQuery
2235
2336_AUTO_ID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
2437
@@ -87,7 +100,7 @@ def parent(self):
87100 parent_path = self ._path [:- 1 ]
88101 return self ._client .document (* parent_path )
89102
90- def _query (self ) -> NoReturn :
103+ def _query (self ) -> BaseQuery :
91104 raise NotImplementedError
92105
93106 def document (self , document_id = None ) -> Any :
@@ -131,13 +144,19 @@ def _parent_info(self) -> Tuple[Any, str]:
131144 expected_prefix = _helpers .DOCUMENT_PATH_DELIMITER .join ((parent_path , self .id ))
132145 return parent_path , expected_prefix
133146
134- def add (self , document_data , document_id = None ) -> NoReturn :
147+ def add (
148+ self , document_data , document_id = None
149+ ) -> Union [Tuple [Any , Any ], Coroutine [Any , Any , Tuple [Any , Any ]]]:
135150 raise NotImplementedError
136151
137- def list_documents (self , page_size = None ) -> NoReturn :
152+ def list_documents (
153+ self , page_size = None
154+ ) -> Union [
155+ Generator [DocumentReference , Any , Any ], AsyncGenerator [DocumentReference , Any ]
156+ ]:
138157 raise NotImplementedError
139158
140- def select (self , field_paths ) -> NoReturn :
159+ def select (self , field_paths ) -> BaseQuery :
141160 """Create a "select" query with this collection as parent.
142161
143162 See
@@ -156,7 +175,7 @@ def select(self, field_paths) -> NoReturn:
156175 query = self ._query ()
157176 return query .select (field_paths )
158177
159- def where (self , field_path , op_string , value ) -> NoReturn :
178+ def where (self , field_path , op_string , value ) -> BaseQuery :
160179 """Create a "where" query with this collection as parent.
161180
162181 See
@@ -180,7 +199,7 @@ def where(self, field_path, op_string, value) -> NoReturn:
180199 query = self ._query ()
181200 return query .where (field_path , op_string , value )
182201
183- def order_by (self , field_path , ** kwargs ) -> NoReturn :
202+ def order_by (self , field_path , ** kwargs ) -> BaseQuery :
184203 """Create an "order by" query with this collection as parent.
185204
186205 See
@@ -202,7 +221,7 @@ def order_by(self, field_path, **kwargs) -> NoReturn:
202221 query = self ._query ()
203222 return query .order_by (field_path , ** kwargs )
204223
205- def limit (self , count ) -> NoReturn :
224+ def limit (self , count ) -> BaseQuery :
206225 """Create a limited query with this collection as parent.
207226
208227 .. note::
@@ -242,7 +261,7 @@ def limit_to_last(self, count):
242261 query = self ._query ()
243262 return query .limit_to_last (count )
244263
245- def offset (self , num_to_skip ) -> NoReturn :
264+ def offset (self , num_to_skip ) -> BaseQuery :
246265 """Skip to an offset in a query with this collection as parent.
247266
248267 See
@@ -260,7 +279,7 @@ def offset(self, num_to_skip) -> NoReturn:
260279 query = self ._query ()
261280 return query .offset (num_to_skip )
262281
263- def start_at (self , document_fields ) -> NoReturn :
282+ def start_at (self , document_fields ) -> BaseQuery :
264283 """Start query at a cursor with this collection as parent.
265284
266285 See
@@ -281,7 +300,7 @@ def start_at(self, document_fields) -> NoReturn:
281300 query = self ._query ()
282301 return query .start_at (document_fields )
283302
284- def start_after (self , document_fields ) -> NoReturn :
303+ def start_after (self , document_fields ) -> BaseQuery :
285304 """Start query after a cursor with this collection as parent.
286305
287306 See
@@ -302,7 +321,7 @@ def start_after(self, document_fields) -> NoReturn:
302321 query = self ._query ()
303322 return query .start_after (document_fields )
304323
305- def end_before (self , document_fields ) -> NoReturn :
324+ def end_before (self , document_fields ) -> BaseQuery :
306325 """End query before a cursor with this collection as parent.
307326
308327 See
@@ -323,7 +342,7 @@ def end_before(self, document_fields) -> NoReturn:
323342 query = self ._query ()
324343 return query .end_before (document_fields )
325344
326- def end_at (self , document_fields ) -> NoReturn :
345+ def end_at (self , document_fields ) -> BaseQuery :
327346 """End query at a cursor with this collection as parent.
328347
329348 See
@@ -344,10 +363,16 @@ def end_at(self, document_fields) -> NoReturn:
344363 query = self ._query ()
345364 return query .end_at (document_fields )
346365
347- def get (self , transaction = None ) -> NoReturn :
366+ def get (
367+ self , transaction = None
368+ ) -> Union [
369+ Generator [DocumentSnapshot , Any , Any ], AsyncGenerator [DocumentSnapshot , Any ]
370+ ]:
348371 raise NotImplementedError
349372
350- def stream (self , transaction = None ) -> NoReturn :
373+ def stream (
374+ self , transaction = None
375+ ) -> Union [Iterator [DocumentSnapshot ], AsyncIterator [DocumentSnapshot ]]:
351376 raise NotImplementedError
352377
353378 def on_snapshot (self , callback ) -> NoReturn :
0 commit comments