Skip to content

Commit

Permalink
improve type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Linchin committed Sep 11, 2024
1 parent 1199f79 commit 0bd5899
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions google/cloud/firestore_v1/async_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""
from __future__ import annotations

from typing import TYPE_CHECKING, List, Optional, Union
from typing import TYPE_CHECKING, Any, AsyncGenerator, List, Optional, Union

from google.api_core import gapic_v1
from google.api_core import retry_async as retries
Expand Down Expand Up @@ -105,8 +105,8 @@ async def _make_stream(
retry: Optional[retries.AsyncRetry] = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
explain_options: Optional[ExplainOptions] = None,
) -> AsyncStreamGenerator[
List[AggregationResult] | query_profile_pb.ExplainMetrics
) -> AsyncGenerator[
[List[AggregationResult] | query_profile_pb.ExplainMetrics], Any
]:
"""Internal method for stream(). Runs the aggregation query.
Expand Down Expand Up @@ -134,7 +134,7 @@ async def _make_stream(
Yields:
List[AggregationResult] | query_profile_pb.ExplainMetrics:
The result of aggregations of this query
The result of aggregations of this query.
"""
metrics: query_profile_pb.ExplainMetrics | None = None

Expand Down
2 changes: 1 addition & 1 deletion google/cloud/firestore_v1/async_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def stream(
timeout: Optional[float] = None,
*,
explain_options: Optional[ExplainOptions] = None,
) -> "AsyncStreamGenerator[DocumentSnapshot]":
) -> AsyncStreamGenerator[DocumentSnapshot]:
"""Read the documents in this collection.
This sends a ``RunQuery`` RPC and then returns a generator which
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/firestore_v1/async_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def stream(
timeout: Optional[float] = None,
*,
explain_options: Optional[ExplainOptions] = None,
) -> AsyncGenerator[async_document.DocumentSnapshot, Any]:
) -> AsyncStreamGenerator[async_document.DocumentSnapshot]:
"""Read the documents in the collection that match this query.
This sends a ``RunQuery`` RPC and then returns a generator which
Expand Down Expand Up @@ -444,7 +444,7 @@ def stream(
explain_metrics will be available on the returned generator.
Returns:
`AsyncGenerator[async_document.DocumentSnapshot, Any]`:
`AsyncStreamGenerator[async_document.DocumentSnapshot]`:
An asynchronous generator of the queryresults.
"""
inner_generator = self._make_stream(
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/firestore_v1/async_stream_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AsyncStreamGenerator(AsyncGenerator[T, Any]):

def __init__(
self,
response_generator: AsyncGenerator[Any, Any],
response_generator: AsyncGenerator[T, Any],
explain_options: Optional[ExplainOptions] = None,
):
self._generator = response_generator
Expand Down
9 changes: 5 additions & 4 deletions google/cloud/firestore_v1/async_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
BaseTransaction,
_BaseTransactional,
)
from google.cloud.firestore_v1.query_results import QueryResultsList

# Types needed only for Type Hints
if TYPE_CHECKING: # pragma: NO COVER
Expand Down Expand Up @@ -179,7 +180,7 @@ async def get(
timeout: float = None,
*,
explain_options: Optional[ExplainOptions] = None,
) -> AsyncGenerator[DocumentSnapshot, Any]:
) -> QueryResultsList[DocumentSnapshot]:
"""
Retrieve a document or a query result from the database.
Expand All @@ -194,9 +195,9 @@ async def get(
Options to enable query profiling for this query. When set,
explain_metrics will be available on the returned generator.
Yields:
.DocumentSnapshot: The next document snapshot that fulfills the
query, or :data:`None` if the document does not exist.
Returns:
QueryResultsList[DocumentSnapshot]: The next document snapshot that
fulfills the query, or :data:`None` if the document does not exist.
"""
kwargs = _helpers.make_retry_timeout_kwargs(retry, timeout)
if isinstance(ref_or_query, AsyncDocumentReference):
Expand Down

0 comments on commit 0bd5899

Please sign in to comment.