Skip to content

Commit d95ea2c

Browse files
committed
fix: add types to some functions
Many return and argument types were missing type annotations.
1 parent d637aee commit d95ea2c

File tree

6 files changed

+28
-11
lines changed

6 files changed

+28
-11
lines changed

google/cloud/firestore_v1/async_batch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from google.api_core import retry_async as retries
2020

2121
from google.cloud.firestore_v1.base_batch import BaseWriteBatch
22+
from google.cloud.firestore_v1.types.write import WriteResult
2223

2324

2425
class AsyncWriteBatch(BaseWriteBatch):
@@ -40,7 +41,7 @@ async def commit(
4041
self,
4142
retry: retries.AsyncRetry | object | None = gapic_v1.method.DEFAULT,
4243
timeout: float | None = None,
43-
) -> list:
44+
) -> list[WriteResult]:
4445
"""Commit the changes accumulated in this batch.
4546
4647
Args:

google/cloud/firestore_v1/async_client.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@
2525
"""
2626
from __future__ import annotations
2727

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+
)
2937

3038
from google.api_core import gapic_v1
3139
from google.api_core import retry_async as retries
@@ -50,9 +58,14 @@
5058

5159
if TYPE_CHECKING: # pragma: NO COVER
5260
import datetime
61+
from typing_extensions import Unpack, TypedDict
5362

5463
from google.cloud.firestore_v1.bulk_writer import BulkWriter
5564

65+
class TransactionKwargs(TypedDict, total=False):
66+
max_attempts: int
67+
read_only: bool
68+
5669

5770
class AsyncClient(BaseClient):
5871
"""Client for interacting with Google Cloud Firestore API.
@@ -410,7 +423,7 @@ def batch(self) -> AsyncWriteBatch:
410423
"""
411424
return AsyncWriteBatch(self)
412425

413-
def transaction(self, **kwargs) -> AsyncTransaction:
426+
def transaction(self, **kwargs: Unpack[TransactionKwargs]) -> AsyncTransaction:
414427
"""Get a transaction that uses this client.
415428
416429
See :class:`~google.cloud.firestore_v1.async_transaction.AsyncTransaction` for

google/cloud/firestore_v1/base_batch.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Helpers for batch requests to the Google Cloud Firestore API."""
1616
from __future__ import annotations
1717
import abc
18-
from typing import Dict, Union
18+
from typing import Any, Dict, Union
1919

2020
# Types needed only for Type Hints
2121
from google.api_core import retry as retries
@@ -67,7 +67,9 @@ def commit(self):
6767
write depend on the implementing class."""
6868
raise NotImplementedError()
6969

70-
def create(self, reference: BaseDocumentReference, document_data: dict) -> None:
70+
def create(
71+
self, reference: BaseDocumentReference, document_data: dict[str, Any]
72+
) -> None:
7173
"""Add a "change" to this batch to create a document.
7274
7375
If the document given by ``reference`` already exists, then this
@@ -120,7 +122,7 @@ def set(
120122
def update(
121123
self,
122124
reference: BaseDocumentReference,
123-
field_updates: dict,
125+
field_updates: dict[str, Any],
124126
option: _helpers.WriteOption | None = None,
125127
) -> None:
126128
"""Add a "change" to update a document.

google/cloud/firestore_v1/base_collection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from google.api_core import retry as retries
3636

3737
from google.cloud.firestore_v1 import _helpers
38+
from google.cloud.firestore_v1.base_document import BaseDocumentReference
3839
from google.cloud.firestore_v1.base_query import QueryType
3940

4041
if TYPE_CHECKING: # pragma: NO COVER
@@ -133,7 +134,7 @@ def _aggregation_query(self) -> BaseAggregationQuery:
133134
def _vector_query(self) -> BaseVectorQuery:
134135
raise NotImplementedError
135136

136-
def document(self, document_id: Optional[str] = None):
137+
def document(self, document_id: Optional[str] = None) -> BaseDocumentReference:
137138
"""Create a sub-document underneath the current collection.
138139
139140
Args:

google/cloud/firestore_v1/base_document.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def _client(self):
418418
return self._reference._client
419419

420420
@property
421-
def exists(self):
421+
def exists(self) -> bool:
422422
"""Existence flag.
423423
424424
Indicates if the document existed at the time this snapshot
@@ -430,7 +430,7 @@ def exists(self):
430430
return self._exists
431431

432432
@property
433-
def id(self):
433+
def id(self) -> str:
434434
"""The document identifier (within its collection).
435435
436436
Returns:
@@ -439,7 +439,7 @@ def id(self):
439439
return self._reference.id
440440

441441
@property
442-
def reference(self):
442+
def reference(self) -> BaseDocumentReference:
443443
"""Document reference corresponding to document that owns this data.
444444
445445
Returns:

google/cloud/firestore_v1/document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def set(
169169

170170
def update(
171171
self,
172-
field_updates: dict,
172+
field_updates: dict[str, Any],
173173
option: _helpers.WriteOption | None = None,
174174
retry: retries.Retry | object | None = gapic_v1.method.DEFAULT,
175175
timeout: float | None = None,

0 commit comments

Comments
 (0)