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

inconsistent type annotations for Document.on_snapshot #26

Closed
igor47 opened this issue Mar 12, 2020 · 1 comment
Closed

inconsistent type annotations for Document.on_snapshot #26

igor47 opened this issue Mar 12, 2020 · 1 comment
Assignees
Labels
api: firestore Issues related to the googleapis/python-firestore API. type: docs Improvement to the documentation for an API.

Comments

@igor47
Copy link

igor47 commented Mar 12, 2020

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.

@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/python-firestore API. label Mar 12, 2020
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Mar 13, 2020
@IlyaFaer IlyaFaer added type: docs Improvement to the documentation for an API. and removed triage me I really want to be triaged. labels Mar 13, 2020
@HemangChothani HemangChothani self-assigned this Mar 16, 2020
@HemangChothani
Copy link
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
Labels
api: firestore Issues related to the googleapis/python-firestore API. type: docs Improvement to the documentation for an API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants