Skip to content

Commit

Permalink
fix: type hinting in collection.py (#688)
Browse files Browse the repository at this point in the history
* fix: Fix type hinting in collection.py

Mostly adding `| None` on all fields that may have `None` as a default value.

* fix: Use Union in type hinting

Use Union to be compatible with 3.7

---------

Co-authored-by: Cedric Khin <[email protected]>
Co-authored-by: Mariatta Wijaya <[email protected]>
  • Loading branch information
3 people authored Feb 17, 2023
1 parent 22af4d7 commit bfb97c2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions google/cloud/firestore_v1/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from google.cloud.firestore_v1 import aggregation
from google.cloud.firestore_v1.watch import Watch
from google.cloud.firestore_v1 import document
from typing import Any, Callable, Generator, Tuple
from typing import Any, Callable, Generator, Tuple, Union

# Types needed only for Type Hints
from google.cloud.firestore_v1.transaction import Transaction
Expand Down Expand Up @@ -79,9 +79,9 @@ def _aggregation_query(self) -> aggregation.AggregationQuery:
def add(
self,
document_data: dict,
document_id: str = None,
document_id: Union[str, None] = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Union[float, None] = None,
) -> Tuple[Any, Any]:
"""Create a document in the Firestore database with the provided data.
Expand Down Expand Up @@ -121,9 +121,9 @@ def add(

def list_documents(
self,
page_size: int = None,
page_size: Union[int, None] = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Union[float, None] = None,
) -> Generator[Any, Any, None]:
"""List all subdocuments of the current collection.
Expand Down Expand Up @@ -156,9 +156,9 @@ def _chunkify(self, chunk_size: int):

def get(
self,
transaction: Transaction = None,
transaction: Union[Transaction, None] = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Union[float, None] = None,
) -> list:
"""Read the documents in this collection.
Expand Down Expand Up @@ -187,9 +187,9 @@ def get(

def stream(
self,
transaction: Transaction = None,
transaction: Union[Transaction, None] = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
timeout: float = None,
timeout: Union[float, None] = None,
) -> Generator[document.DocumentSnapshot, Any, None]:
"""Read the documents in this collection.
Expand Down

0 comments on commit bfb97c2

Please sign in to comment.