Skip to content
This repository was archived by the owner on Aug 30, 2026. It is now read-only.
This repository was archived by the owner on Aug 30, 2026. It is now read-only.

inconsistent type annotations for Document.on_snapshot #26

Closed

Description

@igor47

Looking here (which mirrors the API docs):

callback(Callable[[:class:`~google.cloud.firestore.document.DocumentSnapshot`], NoneType]):
a callback to run when a change occurs

The claim is that the callback invoked by on_snapshot should have type signature Callable[[:class:~google.cloud.firestore.document.DocumentSnapshot], NoneType]. however, just a few lines lower, in the example, it looks like the callback receives three arguments:

def on_snapshot(document_snapshot, changes, read_time):

i tried to understand what's going on by reading the code, and didn't make too much progress. we invoke the callback here:

self._snapshot_callback(
keys,
appliedChanges,
datetime.datetime.fromtimestamp(read_time.seconds, pytz.utc),
)

it looks like there are indeed three arguments passed. appliedChanges appears to be a List[DocumentChange], and the final argument seems to be a datetime.datetime instance. but the first argument... is the result of calling keys() on a document_tree (here:

keys = sorted(updated_tree.keys(), key=key)
) and so maybe is a List[str] ? the self.doc_tree is an instance of WatchDocTree and it's keys() method returns the underlying dict's keys. are those keys actually DocumentSnapshot instances? it maybe sort of seems like it, after tracing through the code a bunch. i'm guessing that the correct type signature for the callback is:

Callable[List[DocumentSnapshot], List[DocumentChange], datetime.datime], None]

but it would be nice if this was confirmed, and the documentation updated to reflect reality.

Activity

  1. added
    type: docsImprovement to the documentation for an API.
    and removed
    triage meI really want to be triaged.
    on Mar 13, 2020
  2. HemangChothani commented on Jul 15, 2020

    @HemangChothani
    Contributor

    Closing as resolved by #79 PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

api: firestoreIssues related to the googleapis/python-firestore API.type: docsImprovement to the documentation for an API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions