| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,7 @@ | |||
| 19 | 19 | from google.api_core import retry_async as retries | |
| 20 | 20 | ||
| 21 | 21 | from google.cloud.firestore_v1.base_batch import BaseWriteBatch | |
| 22 | + from google.cloud.firestore_v1.types.write import WriteResult | ||
| 22 | 23 | ||
| 23 | 24 | ||
| 24 | 25 | class AsyncWriteBatch(BaseWriteBatch): | |
@@ -40,7 +41,7 @@ async def commit( | |||
| 40 | 41 | self, | |
| 41 | 42 | retry: retries.AsyncRetry | object | None = gapic_v1.method.DEFAULT, | |
| 42 | 43 | timeout: float | None = None, | |
| 43 | - ) -> list: | ||
| 44 | + ) -> list[WriteResult]: | ||
| 44 | 45 | """Commit the changes accumulated in this batch. | |
| 45 | 46 | ||
| 46 | 47 | Args: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,15 @@ | |||
| 25 | 25 | """ | |
| 26 | 26 | from __future__ import annotations | |
| 27 | 27 | ||
| 28 | - from typing import TYPE_CHECKING, Any, AsyncGenerator, Iterable, List, Optional, Union | ||
| 28 | + from typing import ( | ||
| 29 | + TYPE_CHECKING, | ||
| 30 | + Any, | ||
| 31 | + AsyncGenerator, | ||
| 32 | + Iterable, | ||
| 33 | + List, | ||
| 34 | + Optional, | ||
| 35 | + Union, | ||
| 36 | + ) | ||
| 29 | 37 | ||
| 30 | 38 | from google.api_core import gapic_v1 | |
| 31 | 39 | from google.api_core import retry_async as retries | |
@@ -40,6 +48,7 @@ | |||
| 40 | 48 | from google.cloud.firestore_v1.async_transaction import AsyncTransaction | |
| 41 | 49 | from google.cloud.firestore_v1.base_client import _parse_batch_get # type: ignore | |
| 42 | 50 | from google.cloud.firestore_v1.base_client import _CLIENT_INFO, BaseClient, _path_helper | |
| 51 | + from google.cloud.firestore_v1.base_transaction import MAX_ATTEMPTS | ||
| 43 | 52 | from google.cloud.firestore_v1.field_path import FieldPath | |
| 44 | 53 | from google.cloud.firestore_v1.services.firestore import ( | |
| 45 | 54 | async_client as firestore_client, | |
@@ -410,7 +419,9 @@ def batch(self) -> AsyncWriteBatch: | |||
| 410 | 419 | """ | |
| 411 | 420 | return AsyncWriteBatch(self) | |
| 412 | 421 | ||
| 413 | - def transaction(self, **kwargs) -> AsyncTransaction: | ||
| 422 | + def transaction( | ||
| 423 | + self, max_attempts: int = MAX_ATTEMPTS, read_only: bool = False | ||
| 424 | + ) -> AsyncTransaction: | ||
| 414 | 425 | """Get a transaction that uses this client. | |
| 415 | 426 | ||
| 416 | 427 | See :class:`~google.cloud.firestore_v1.async_transaction.AsyncTransaction` for | |
@@ -426,4 +437,4 @@ def transaction(self, **kwargs) -> AsyncTransaction: | |||
| 426 | 437 | :class:`~google.cloud.firestore_v1.async_transaction.AsyncTransaction`: | |
| 427 | 438 | A transaction attached to this client. | |
| 428 | 439 | """ | |
| 429 | - return AsyncTransaction(self, **kwargs) | ||
| 440 | + return AsyncTransaction(self, max_attempts=max_attempts, read_only=read_only) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,7 @@ | |||
| 15 | 15 | """Classes for representing collections for the Google Cloud Firestore API.""" | |
| 16 | 16 | from __future__ import annotations | |
| 17 | 17 | ||
| 18 | - from typing import TYPE_CHECKING, Any, AsyncGenerator, Optional, Tuple | ||
| 18 | + from typing import TYPE_CHECKING, Any, AsyncGenerator, Optional, Tuple, cast | ||
| 19 | 19 | ||
| 20 | 20 | from google.api_core import gapic_v1 | |
| 21 | 21 | from google.api_core import retry_async as retries | |
@@ -153,7 +153,8 @@ def document(self, document_id: str | None = None) -> AsyncDocumentReference: | |||
| 153 | 153 | :class:`~google.cloud.firestore_v1.document.async_document.AsyncDocumentReference`: | |
| 154 | 154 | The child document. | |
| 155 | 155 | """ | |
| 156 | - return super(AsyncCollectionReference, self).document(document_id) | ||
| 156 | + doc = super(AsyncCollectionReference, self).document(document_id) | ||
| 157 | + return cast("AsyncDocumentReference", doc) | ||
| 157 | 158 | ||
| 158 | 159 | async def list_documents( | |
| 159 | 160 | self, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,7 @@ | |||
| 15 | 15 | """Helpers for batch requests to the Google Cloud Firestore API.""" | |
| 16 | 16 | from __future__ import annotations | |
| 17 | 17 | import abc | |
| 18 | - from typing import Dict, Union | ||
| 18 | + from typing import Any, Dict, Union | ||
| 19 | 19 | ||
| 20 | 20 | # Types needed only for Type Hints | |
| 21 | 21 | from google.api_core import retry as retries | |
@@ -67,7 +67,9 @@ def commit(self): | |||
| 67 | 67 | write depend on the implementing class.""" | |
| 68 | 68 | raise NotImplementedError() | |
| 69 | 69 | ||
| 70 | - def create(self, reference: BaseDocumentReference, document_data: dict) -> None: | ||
| 70 | + def create( | ||
| 71 | + self, reference: BaseDocumentReference, document_data: dict[str, Any] | ||
| 72 | + ) -> None: | ||
| 71 | 73 | """Add a "change" to this batch to create a document. | |
| 72 | 74 | ||
| 73 | 75 | If the document given by ``reference`` already exists, then this | |
@@ -120,7 +122,7 @@ def set( | |||
| 120 | 122 | def update( | |
| 121 | 123 | self, | |
| 122 | 124 | reference: BaseDocumentReference, | |
| 123 | - field_updates: dict, | ||
| 125 | + field_updates: dict[str, Any], | ||
| 124 | 126 | option: _helpers.WriteOption | None = None, | |
| 125 | 127 | ) -> None: | |
| 126 | 128 | """Add a "change" to update a document. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,7 +57,7 @@ | |||
| 57 | 57 | DocumentSnapshot, | |
| 58 | 58 | ) | |
| 59 | 59 | from google.cloud.firestore_v1.base_query import BaseQuery | |
| 60 | - from google.cloud.firestore_v1.base_transaction import BaseTransaction | ||
| 60 | + from google.cloud.firestore_v1.base_transaction import MAX_ATTEMPTS, BaseTransaction | ||
| 61 | 61 | from google.cloud.firestore_v1.bulk_writer import BulkWriter, BulkWriterOptions | |
| 62 | 62 | from google.cloud.firestore_v1.field_path import render_field_path | |
| 63 | 63 | from google.cloud.firestore_v1.services.firestore import client as firestore_client | |
@@ -497,7 +497,9 @@ def collections( | |||
| 497 | 497 | def batch(self) -> BaseWriteBatch: | |
| 498 | 498 | raise NotImplementedError | |
| 499 | 499 | ||
| 500 | - def transaction(self, **kwargs) -> BaseTransaction: | ||
| 500 | + def transaction( | ||
| 501 | + self, max_attempts: int = MAX_ATTEMPTS, read_only: bool = False | ||
| 502 | + ) -> BaseTransaction: | ||
| 501 | 503 | raise NotImplementedError | |
| 502 | 504 | ||
| 503 | 505 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,7 @@ | |||
| 35 | 35 | from google.api_core import retry as retries | |
| 36 | 36 | ||
| 37 | 37 | from google.cloud.firestore_v1 import _helpers | |
| 38 | + from google.cloud.firestore_v1.base_document import BaseDocumentReference | ||
| 38 | 39 | from google.cloud.firestore_v1.base_query import QueryType | |
| 39 | 40 | ||
| 40 | 41 | if TYPE_CHECKING: # pragma: NO COVER | |
@@ -133,7 +134,7 @@ def _aggregation_query(self) -> BaseAggregationQuery: | |||
| 133 | 134 | def _vector_query(self) -> BaseVectorQuery: | |
| 134 | 135 | raise NotImplementedError | |
| 135 | 136 | ||
| 136 | - def document(self, document_id: Optional[str] = None): | ||
| 137 | + def document(self, document_id: Optional[str] = None) -> BaseDocumentReference: | ||
| 137 | 138 | """Create a sub-document underneath the current collection. | |
| 138 | 139 | ||
| 139 | 140 | Args: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -418,7 +418,7 @@ def _client(self): | |||
| 418 | 418 | return self._reference._client | |
| 419 | 419 | ||
| 420 | 420 | @property | |
| 421 | - def exists(self): | ||
| 421 | + def exists(self) -> bool: | ||
| 422 | 422 | """Existence flag. | |
| 423 | 423 | ||
| 424 | 424 | Indicates if the document existed at the time this snapshot | |
@@ -430,7 +430,7 @@ def exists(self): | |||
| 430 | 430 | return self._exists | |
| 431 | 431 | ||
| 432 | 432 | @property | |
| 433 | - def id(self): | ||
| 433 | + def id(self) -> str: | ||
| 434 | 434 | """The document identifier (within its collection). | |
| 435 | 435 | ||
| 436 | 436 | Returns: | |
@@ -439,7 +439,7 @@ def id(self): | |||
| 439 | 439 | return self._reference.id | |
| 440 | 440 | ||
| 441 | 441 | @property | |
| 442 | - def reference(self): | ||
| 442 | + def reference(self) -> BaseDocumentReference: | ||
| 443 | 443 | """Document reference corresponding to document that owns this data. | |
| 444 | 444 | ||
| 445 | 445 | Returns: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,7 @@ | |||
| 39 | 39 | ||
| 40 | 40 | # Types needed only for Type Hints | |
| 41 | 41 | from google.cloud.firestore_v1.base_document import DocumentSnapshot | |
| 42 | + from google.cloud.firestore_v1.base_transaction import MAX_ATTEMPTS | ||
| 42 | 43 | from google.cloud.firestore_v1.batch import WriteBatch | |
| 43 | 44 | from google.cloud.firestore_v1.collection import CollectionReference | |
| 44 | 45 | from google.cloud.firestore_v1.document import DocumentReference | |
@@ -391,7 +392,9 @@ def batch(self) -> WriteBatch: | |||
| 391 | 392 | """ | |
| 392 | 393 | return WriteBatch(self) | |
| 393 | 394 | ||
| 394 | - def transaction(self, **kwargs) -> Transaction: | ||
| 395 | + def transaction( | ||
| 396 | + self, max_attempts: int = MAX_ATTEMPTS, read_only: bool = False | ||
| 397 | + ) -> Transaction: | ||
| 395 | 398 | """Get a transaction that uses this client. | |
| 396 | 399 | ||
| 397 | 400 | See :class:`~google.cloud.firestore_v1.transaction.Transaction` for | |
@@ -407,4 +410,4 @@ def transaction(self, **kwargs) -> Transaction: | |||
| 407 | 410 | :class:`~google.cloud.firestore_v1.transaction.Transaction`: | |
| 408 | 411 | A transaction attached to this client. | |
| 409 | 412 | """ | |
| 410 | - return Transaction(self, **kwargs) | ||
| 413 | + return Transaction(self, max_attempts=max_attempts, read_only=read_only) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -169,7 +169,7 @@ def set( | |||
| 169 | 169 | ||
| 170 | 170 | def update( | |
| 171 | 171 | self, | |
| 172 | - field_updates: dict, | ||
| 172 | + field_updates: dict[str, Any], | ||
| 173 | 173 | option: _helpers.WriteOption | None = None, | |
| 174 | 174 | retry: retries.Retry | object | None = gapic_v1.method.DEFAULT, | |
| 175 | 175 | timeout: float | None = None, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments