Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

Commit d3796b0

Browse files
committed
improve docstring and type annotation
1 parent f2a39f0 commit d3796b0

2 files changed

Lines changed: 19 additions & 21 deletions

File tree

google/cloud/firestore_v1/base_pipeline.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -273,25 +273,22 @@ def find_nearest(
273273
stages.FindNearest(field, vector, distance_measure, options)
274274
)
275275

276-
def literals(
277-
self,
278-
*documents: Selectable,
279-
) -> "_BasePipeline":
276+
def literals(self, *documents: str | Selectable) -> "_BasePipeline":
280277
"""
281278
Returns documents from a fixed set of predefined document objects.
282279
283280
This stage is commonly used for testing other stages in isolation, though it can
284281
also be used as inputs to join conditions.
285282
286283
Example:
284+
>>> from google.cloud.firestore_v1.pipeline_expressions import Constant
285+
>>> documents = [
286+
... {"name": "joe", "age": 10},
287+
... {"name": "bob", "age": 30},
288+
... {"name": "alice", "age": 40}
289+
... ]
287290
>>> pipeline = client.pipeline()
288-
... .literals(
289-
... [
290-
... {"name": "joe", "age": 10},
291-
... {"name": "bob", "age": 30},
292-
... {"name": "alice", "age": 40}
293-
... ]
294-
... )
291+
... .literals(Constant.of(documents))
295292
... .where(field("age").lessThan(35))
296293
297294
Output documents:
@@ -317,13 +314,11 @@ def literals(
317314
318315
Example:
319316
>>> from google.cloud.firestore_v1.pipeline_expressions import Constant
320-
>>> pipeline = client.pipeline()
321-
... .literals(
322-
... [
323-
... {"x": Constant.of("foo-bar-baz").char_length()},
324-
... {"x": Constant.of("bar").char_length()}
325-
... ]
326-
... )
317+
>>> documents = [
318+
... {"x": Constant.of("foo-bar-baz").char_length()},
319+
... {"x": Constant.of("bar").char_length()}
320+
... ]
321+
>>> pipeline = client.pipeline().literals(Constant.of(documents))
327322
328323
Output documents:
329324
```json
@@ -334,9 +329,12 @@ def literals(
334329
```
335330
336331
Args:
337-
documents: A fixed set of predefined document objects.
332+
documents: A `str` or `Selectable` expression. If a `str`, it's
333+
treated as a field path to an array of documents.
334+
If a `Selectable`, it's usually a `Constant`
335+
containing an array of documents (as dictionaries).
338336
Returns:
339-
A new Pipeline object with this stage appended to the stage list
337+
A new Pipeline object with this stage appended to the stage list.
340338
"""
341339
return self._append(stages.Literals(*documents))
342340

google/cloud/firestore_v1/pipeline_stages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def _pb_args(self):
345345
class Literals(Stage):
346346
"""Returns documents from a fixed set of predefined document objects."""
347347

348-
def __init__(self, *documents: Selectable):
348+
def __init__(self, *documents: str | Selectable):
349349
super().__init__("literals")
350350
self.documents = documents
351351

0 commit comments

Comments
 (0)