Skip to content

fix: update the async transactional types to not require extra awaits #1045

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

Conversation

jekozyra
Copy link
Contributor

@jekozyra jekozyra commented May 10, 2025

I updated the types of a few things in async_transactional to ensure that when a function wrapped with @async_transactional is called:

  • the return type of the inner function is correctly detected as the correct final result by the typechecker

  • we can pass additional arguments to the wrapped function without the typechecker complaining

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea

  • Ensure the tests and linter pass

  • Code coverage does not decrease (if any source code was changed)

  • Appropriate docs were updated (if necessary)

Fixes #1044 🦕

@product-auto-label product-auto-label bot added size: s Pull request size is small. api: firestore Issues related to the googleapis/python-firestore API. labels May 10, 2025
@jekozyra jekozyra force-pushed the jillian/update-types-for-async-transactions branch from b216867 to ca23405 Compare May 10, 2025 04:59
@jekozyra jekozyra marked this pull request as ready for review May 10, 2025 04:59
@jekozyra jekozyra requested review from a team as code owners May 10, 2025 04:59
@jekozyra
Copy link
Contributor Author

@wu-hui could I get a review here please?

daniel-sanche
daniel-sanche previously approved these changes May 21, 2025
@@ -41,6 +52,10 @@
from google.cloud.firestore_v1.query_profile import ExplainOptions


T = TypeVar("T")
P = ParamSpec("P")
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like ParamSpec was added in python 3.10, and we need to support 3.8

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added typing_extensions to support expanded type hinting for older python versions. Let me know if that works, otherwise I'll come up with something more hacky for the signatures.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, adding an extra dependency to setup.py isn't an option unfortunately

Let me know if you're able to experiment with getting this working, or I can try to take it from here if you don't have the capacity

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated it to use a protocol instead. The type checking still looks to achieve the intended result on my end.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, it looks like I was wrong when I said we support 3.8+. We actually still support 3.7 here, which doesn't support Protocol either.

If we can keep some of this confined to the TYPE_CHECKING block, that could be a solution, since we our mypy checks run against a more recent version of Python (Maybe ParamSpec could work that way?). Or maybe there's another way to accomplish the same thing

If you're interested in running some of these tests locally, there's a short section in the CONTRIBUTING file on using nox. It works well with pyenv. Or you can let me know if you want me to take more of this on

I'll take another look at this next week, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not going to have time to continue looking at this for the forseeable future.

@jekozyra jekozyra force-pushed the jillian/update-types-for-async-transactions branch from 69ff68b to 576a8a8 Compare May 29, 2025 05:06
@daniel-sanche
Copy link
Contributor

Fixed in #1066

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. size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The type of async_transactional is incorrect
4 participants