Open
Description
The return of the decorated function evaluates correctly at runtime but the typechecker thinks that it is Coroutine[Unknown, Unknown, Unknown], which is incorrect.
Environment details
- OS type and version: OSX 15.4.1
- Python version: 3.13
- pip version: 24.2
google-cloud-firestore
version: 2.20.2
pyright 1.1.396 is used as the typechecker.
Steps to reproduce
- Use the
async_transactional
decorator as detailed in the docs - The return of the decorated function evaluates correctly at runtime but the typechecker thinks that it is
Coroutine[Unknown, Unknown, Unknown]
Code example
import asyncio
import firebase_admin
from firebase_admin import firestore_async
from google.cloud.firestore_v1 import AsyncClient as AsyncFirestoreClient
from google.cloud.firestore_v1.async_transaction import (
AsyncTransaction,
async_transactional,
)
async def func(db: AsyncFirestoreClient) -> None:
transaction = db.transaction()
city_ref = db.collection("cities").document("SF")
@async_transactional
async def update_in_transaction(transaction: AsyncTransaction) -> str:
snapshot = await city_ref.get(transaction=transaction)
transaction.update(city_ref, {"population": snapshot.get("population") + 1})
return "done"
res = await update_in_transaction(transaction)
print(type(res)) # evaluates to <class 'str'> at run time but Coroutine[Unknown, Unknown, Unknown] in the typechecker
async def func2(db: AsyncFirestoreClient) -> str:
transaction = db.transaction()
city_ref = db.collection("cities").document("SF")
@async_transactional
async def update_in_transaction(transaction: AsyncTransaction) -> str:
snapshot = await city_ref.get(transaction=transaction)
transaction.update(city_ref, {"population": snapshot.get("population") + 1})
return "done"
return await update_in_transaction(transaction) # typechecker errors
if __name__ == "__main__":
app = firebase_admin.initialize_app(
options={"projectId": "poggio-local-experiments"}
)
db = firestore_async.client(app)
asyncio.run(func(db=db))
asyncio.run(func2(db=db))