Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the type 'Optional' to all optional parameters for async functions #855

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -23,9 +23,9 @@
from google.api_core import gapic_v1
from google.api_core import retry_async as retries

from typing import List, Union, AsyncGenerator

from typing import List, Union, AsyncGenerator, Optional

from google.cloud.firestore_v1.async_transaction import AsyncTransaction
from google.cloud.firestore_v1.base_aggregation import (
AggregationResult,
_query_response_to_result,
Expand All @@ -44,7 +44,7 @@ def __init__(

async def get(
self,
transaction=None,
transaction: Optional[AsyncTransaction] = None,
retry: Union[
retries.AsyncRetry, None, gapic_v1.method._MethodDefault
] = gapic_v1.method.DEFAULT,
Expand Down Expand Up @@ -78,7 +78,7 @@ async def get(

async def stream(
self,
transaction=None,
transaction: Optional[AsyncTransaction] = None,
retry: Union[
retries.AsyncRetry, None, gapic_v1.method._MethodDefault
] = gapic_v1.method.DEFAULT,
Expand Down
6 changes: 4 additions & 2 deletions google/cloud/firestore_v1/async_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from google.api_core import retry_async as retries

from google.cloud.firestore_v1.base_batch import BaseWriteBatch
from google.cloud.firestore_v1.types import WriteResult
from typing import Optional


class AsyncWriteBatch(BaseWriteBatch):
Expand All @@ -39,8 +41,8 @@ def __init__(self, client) -> None:
async def commit(
self,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
) -> list:
timeout: Optional[float] = None,
) -> list[WriteResult]:
"""Commit the changes accumulated in this batch.

Args:
Expand Down
8 changes: 4 additions & 4 deletions google/cloud/firestore_v1/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ def document(self, *document_path: str) -> AsyncDocumentReference:
async def get_all(
self,
references: List[AsyncDocumentReference],
field_paths: Iterable[str] = None,
transaction=None,
field_paths: Optional[Iterable[str]] = None,
transaction: Optional[AsyncTransaction] = None,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> AsyncGenerator[DocumentSnapshot, Any]:
"""Retrieve a batch of documents.

Expand Down Expand Up @@ -285,7 +285,7 @@ async def get_all(
async def collections(
self,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> AsyncGenerator[AsyncCollectionReference, Any]:
"""List top-level collections of the client's database.

Expand Down
27 changes: 13 additions & 14 deletions google/cloud/firestore_v1/async_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
_item_to_document_ref,
)
from google.cloud.firestore_v1 import async_query, async_document, async_aggregation
from google.cloud.firestore_v1.async_transaction import AsyncTransaction
from google.protobuf.timestamp_pb2 import Timestamp

from google.cloud.firestore_v1.document import DocumentReference

from typing import AsyncIterator
from typing import Any, AsyncGenerator, Tuple

# Types needed only for Type Hints
from google.cloud.firestore_v1.transaction import Transaction
from typing import AsyncGenerator, Tuple, Optional


class AsyncCollectionReference(BaseCollectionReference[async_query.AsyncQuery]):
Expand Down Expand Up @@ -84,10 +83,10 @@ async def _chunkify(self, chunk_size: int):
async def add(
self,
document_data: dict,
document_id: str = None,
document_id: Optional[str] = None,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
) -> Tuple[Any, Any]:
timeout: Optional[float] = None,
) -> Tuple[Timestamp, async_document.AsyncDocumentReference]:
"""Create a document in the Firestore database with the provided data.

Args:
Expand Down Expand Up @@ -125,7 +124,7 @@ async def add(
return write_result.update_time, document_ref

def document(
self, document_id: str = None
self, document_id: Optional[str] = None
) -> async_document.AsyncDocumentReference:
"""Create a sub-document underneath the current collection.

Expand All @@ -143,9 +142,9 @@ def document(

async def list_documents(
self,
page_size: int = None,
page_size: Optional[int] = None,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> AsyncGenerator[DocumentReference, None]:
"""List all subdocuments of the current collection.

Expand Down Expand Up @@ -176,9 +175,9 @@ async def list_documents(

async def get(
self,
transaction: Transaction = None,
transaction: Optional[AsyncTransaction] = None,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> list:
"""Read the documents in this collection.

Expand Down Expand Up @@ -207,9 +206,9 @@ async def get(

async def stream(
self,
transaction: Transaction = None,
transaction: Optional[AsyncTransaction] = None,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> AsyncIterator[async_document.DocumentSnapshot]:
"""Read the documents in this collection.

Expand Down
25 changes: 13 additions & 12 deletions google/cloud/firestore_v1/async_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
_first_write_result,
)
from google.cloud.firestore_v1 import _helpers
from google.cloud.firestore_v1.async_transaction import AsyncTransaction
from google.cloud.firestore_v1.types import write
from google.protobuf.timestamp_pb2 import Timestamp
from typing import AsyncGenerator, Iterable
from typing import AsyncGenerator, Iterable, Optional


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -66,7 +67,7 @@ async def create(
self,
document_data: dict,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> write.WriteResult:
"""Create the current document in the Firestore database.

Expand Down Expand Up @@ -96,7 +97,7 @@ async def set(
document_data: dict,
merge: bool = False,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> write.WriteResult:
"""Replace the current document in the Firestore database.

Expand Down Expand Up @@ -134,9 +135,9 @@ async def set(
async def update(
self,
field_updates: dict,
option: _helpers.WriteOption = None,
option: Optional[_helpers.WriteOption] = None,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> write.WriteResult:
"""Update an existing document in the Firestore database.

Expand Down Expand Up @@ -291,9 +292,9 @@ async def update(

async def delete(
self,
option: _helpers.WriteOption = None,
option: Optional[_helpers.WriteOption] = None,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> Timestamp:
"""Delete the current document in the Firestore database.

Expand Down Expand Up @@ -325,10 +326,10 @@ async def delete(

async def get(
self,
field_paths: Iterable[str] = None,
transaction=None,
field_paths: Optional[Iterable[str]] = None,
transaction: Optional[AsyncTransaction] = None,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> DocumentSnapshot:
"""Retrieve a snapshot of the current document.

Expand Down Expand Up @@ -394,9 +395,9 @@ async def get(

async def collections(
self,
page_size: int = None,
page_size: Optional[int] = None,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> AsyncGenerator:
"""List subcollections of the current document.

Expand Down
14 changes: 7 additions & 7 deletions google/cloud/firestore_v1/async_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

if TYPE_CHECKING: # pragma: NO COVER
# Types needed only for Type Hints
from google.cloud.firestore_v1.transaction import Transaction
from google.cloud.firestore_v1.async_transaction import AsyncTransaction
from google.cloud.firestore_v1.field_path import FieldPath


Expand Down Expand Up @@ -171,9 +171,9 @@ async def _chunkify(

async def get(
self,
transaction: Transaction = None,
transaction: Optional[AsyncTransaction] = None,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> list:
"""Read the documents in the collection that match this query.

Expand Down Expand Up @@ -266,9 +266,9 @@ def avg(

async def stream(
self,
transaction=None,
transaction: Optional[AsyncTransaction] = None,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> AsyncGenerator[async_document.DocumentSnapshot, None]:
"""Read the documents in the collection that match this query.

Expand Down Expand Up @@ -379,9 +379,9 @@ def _get_query_class():

async def get_partitions(
self,
partition_count,
partition_count: int,
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> AsyncGenerator[QueryPartition, None]:
"""Partition a query for parallelization.

Expand Down
12 changes: 6 additions & 6 deletions google/cloud/firestore_v1/async_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from google.cloud.firestore_v1.async_document import AsyncDocumentReference
from google.cloud.firestore_v1.async_document import DocumentSnapshot
from google.cloud.firestore_v1.async_query import AsyncQuery
from typing import Any, AsyncGenerator, Callable, Coroutine
from typing import Any, AsyncGenerator, Callable, Coroutine, Optional, Union

# Types needed only for Type Hints
from google.cloud.firestore_v1.client import Client
Expand Down Expand Up @@ -82,7 +82,7 @@ def _add_write_pbs(self, write_pbs: list) -> None:

super(AsyncTransaction, self)._add_write_pbs(write_pbs)

async def _begin(self, retry_id: bytes = None) -> None:
async def _begin(self, retry_id: Optional[bytes] = None) -> None:
"""Begin the transaction.

Args:
Expand Down Expand Up @@ -152,9 +152,9 @@ async def _commit(self) -> list:

async def get_all(
self,
references: list,
references: list[AsyncDocumentReference],
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> AsyncGenerator[DocumentSnapshot, Any]:
"""Retrieves multiple documents from Firestore.

Expand All @@ -175,9 +175,9 @@ async def get_all(

async def get(
self,
ref_or_query,
ref_or_query: Union[AsyncDocumentReference, AsyncQuery],
retry: retries.AsyncRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Optional[float] = None,
) -> AsyncGenerator[DocumentSnapshot, Any]:
"""
Retrieve a document or a query result from the database.
Expand Down
Loading