Skip to content

fix(firestore): add generic typing for DocumentSnapshot - #18587

Open
daniel-sanche wants to merge 2 commits into
mainfrom
fix_firestore_snapshot_typing
Open

daniel-sanche wants to merge 2 commits into
mainfrom
fix_firestore_snapshot_typing

Conversation

@daniel-sanche

Copy link
Copy Markdown
Contributor

DocumentSnapshot can be used with sync or async document reference types, which can result in confusing or incorrect type annotations upstream

This PR makes DocumentSnapshot into a Generic, so it can specify what type of reference it holds.

Fixes #15367

@daniel-sanche
daniel-sanche requested a review from a team as a code owner October 7, 2026 00:02

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces generic typing to DocumentSnapshot to specify the associated document reference type (DocumentReference or AsyncDocumentReference) across various Firestore client, query, and transaction modules. Feedback highlights a compatibility issue where using a string literal as a TypeVar bound (bound="BaseDocumentReference") will raise a TypeError at runtime in Python versions prior to 3.12. It is recommended to define DocRefType after BaseDocumentReference is fully defined so the actual class object can be used as the bound.

Comment thread packages/google-cloud-firestore/google/cloud/firestore_v1/base_document.py Outdated

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type Mismatch DocumentSnapshot of AsyncCollectionReference

1 participant