Skip to content

Commit 42b66bf

Browse files
committed
refactor(firestore): restore precise return types and docstrings on decode_value
- Restore full Union return type with _BSONType on decode_value. - Restore Returns and Raises docstring sections in decode_value matching base branch. - Remove unused _BSON_DECODERS import from _helpers.py. - Revert extraneous changes to pipeline_result.py. Towards #18402
1 parent 9d5e3ea commit 42b66bf

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

packages/google-cloud-firestore/google/cloud/firestore_v1/_helpers.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import google
4545
from google.cloud import exceptions # type: ignore
4646
from google.cloud.firestore_v1 import transforms, types
47-
from google.cloud.firestore_v1.bson import _BSON_DECODERS, _BSONType
47+
from google.cloud.firestore_v1.bson import _BSONType
4848
from google.cloud.firestore_v1.field_path import FieldPath, parse_field_path
4949
from google.cloud.firestore_v1.types import common, document, write
5050
from google.cloud.firestore_v1.types.write import DocumentTransform
@@ -347,7 +347,22 @@ def reference_value_to_document(reference_value, client) -> Any:
347347
return document
348348

349349

350-
def decode_value(value, client=None) -> Any:
350+
def decode_value(
351+
value, client=None
352+
) -> Union[
353+
None,
354+
bool,
355+
int,
356+
float,
357+
list,
358+
datetime.datetime,
359+
str,
360+
bytes,
361+
dict,
362+
GeoPoint,
363+
Vector,
364+
_BSONType,
365+
]:
351366
"""Converts a Firestore protobuf ``Value`` to a native Python value.
352367
353368
Args:
@@ -357,10 +372,15 @@ def decode_value(value, client=None) -> Any:
357372
A client that has a document factory.
358373
359374
Returns:
360-
Any: A native Python value converted from the ``value``.
375+
Union[NoneType, bool, int, float, datetime.datetime, \
376+
str, bytes, dict, ~google.cloud.Firestore.GeoPoint, \
377+
~google.cloud.firestore_v1.vector.Vector, \
378+
~google.cloud.firestore_v1.bson._BSONType]: A native \
379+
Python value converted from the ``value``.
361380
362381
Raises:
363-
ValueError: If ``value_type`` is unknown or unsupported.
382+
NotImplementedError: If the ``value_type`` is ``reference_value``.
383+
ValueError: If the ``value_type`` is unknown.
364384
"""
365385
value_pb = getattr(value, "_pb", value)
366386
value_type = value_pb.WhichOneof("value_type")

packages/google-cloud-firestore/google/cloud/firestore_v1/pipeline_result.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
from google.cloud.firestore_v1.async_transaction import AsyncTransaction
4545
from google.cloud.firestore_v1.base_client import BaseClient
4646
from google.cloud.firestore_v1.base_document import BaseDocumentReference
47-
from google.cloud.firestore_v1.bson import _BSONType
4847
from google.cloud.firestore_v1.client import Client
4948
from google.cloud.firestore_v1.pipeline import Pipeline
5049
from google.cloud.firestore_v1.pipeline_expressions import Constant
@@ -139,7 +138,7 @@ def __eq__(self, other: object) -> bool:
139138
return NotImplemented
140139
return (self._ref == other._ref) and (self._fields_pb == other._fields_pb)
141140

142-
def data(self) -> dict | "Vector" | "_BSONType" | None:
141+
def data(self) -> dict | "Vector" | None:
143142
"""
144143
Retrieves all fields in the result.
145144

0 commit comments

Comments
 (0)