Skip to content

Commit

Permalink
aggregation related type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Linchin committed Aug 6, 2024
1 parent 7439e76 commit bb60ce0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions google/cloud/firestore_v1/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, Generator, Optional, Tuple, Union
from typing import TYPE_CHECKING, Generator, List, Optional, Tuple, Union

from google.api_core import exceptions, gapic_v1
from google.api_core import retry as retries
Expand Down Expand Up @@ -133,7 +133,7 @@ def _make_stream(
retry: Optional[retries.Retry] = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
explain_options: Optional[ExplainOptions] = None,
) -> Generator[Tuple[Optional[DocumentSnapshot], Optional[ExplainMetrics]]]:
) -> Generator[Tuple[Optional[List[AggregationResult]], Optional[ExplainMetrics]]]:
"""Internal method for stream(). Runs the aggregation query.
This sends a ``RunAggregationQuery`` RPC and then returns a generator
Expand All @@ -158,7 +158,7 @@ def _make_stream(
explain_metrics will be available on the returned generator.
Yields:
Tuple[Optional[DocumentSnapshot], Optional[ExplainMetrics]]:
Tuple[Optional[List[AggregationResult]], Optional[ExplainMetrics]]:
The result of aggregations of this query.
"""

Expand Down
19 changes: 13 additions & 6 deletions google/cloud/firestore_v1/base_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
from typing import (
TYPE_CHECKING,
Any,
AsyncGenerator,
Coroutine,
Generator,
List,
Optional,
Tuple,
Expand All @@ -49,7 +47,12 @@
# Types needed only for Type Hints
if TYPE_CHECKING: # pragma: NO COVER
from google.cloud.firestore_v1 import transaction
from google.cloud.firestore_v1.async_stream_generator import AsyncStreamGenerator
from google.cloud.firestore_v1.query_profile import ExplainOptions
from google.cloud.firestore_v1.stream_generator import (
QueryResultsList,
StreamGenerator,
)


class AggregationResult(object):
Expand Down Expand Up @@ -236,7 +239,10 @@ def get(
timeout: float | None = None,
*,
explain_options: Optional[ExplainOptions] = None,
) -> List[AggregationResult] | Coroutine[Any, Any, List[AggregationResult]]:
) -> (
QueryResultsList[AggregationResult]
| Coroutine[Any, Any, List[AggregationResult]]
):
"""Runs the aggregation query.
This sends a ``RunAggregationQuery`` RPC and returns a list of aggregation results in the stream of ``RunAggregationQueryResponse`` messages.
Expand All @@ -258,7 +264,8 @@ def get(
explain_metrics will be available on the returned generator.
Returns:
list: The aggregation query results
QueryResultsList[AggregationResult] | Coroutine[Any, Any, List[AggregationResult]]:
The aggregation query results.
"""

Expand All @@ -271,8 +278,8 @@ def stream(
*,
explain_options: Optional[ExplainOptions] = None,
) -> (
Generator[List[AggregationResult], Any, None]
| AsyncGenerator[List[AggregationResult], None]
StreamGenerator[List[AggregationResult], Any, None]
| AsyncStreamGenerator[List[AggregationResult], Any, None]
):
"""Runs the aggregation query.
Expand Down

0 comments on commit bb60ce0

Please sign in to comment.