typing: propagate result types through async APIs - #797
Open
bringhurst wants to merge 1 commit into
Open
Conversation
## Why is this needed? Kazoo's async methods return a bare IAsyncResult, so get() becomes Any and synchronous wrappers need casts. This makes the public annotations less useful. This is the first step toward typing the full request path. A follow-up can tie each wire request to its response with a generic _submit helper, then carry that type through the pending queue. ## Proposed Changes - Make IAsyncResult generic in the value it carries. - Add result types to the public async client methods. - Remove casts that are no longer needed. - Type ignored callback and handler-specific wait() returns as object. - Add static checks for the public API. ## Does this PR introduce any breaking change? No. Runtime APIs and behavior stay the same.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #797 +/- ##
==========================================
- Coverage 96.65% 95.42% -1.23%
==========================================
Files 27 27
Lines 3554 3870 +316
==========================================
+ Hits 3435 3693 +258
- Misses 119 177 +58 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
That's nice! Takes something off my todo list as well! |
|
|
||
|
|
||
| SpawnedFunc = Callable[..., None] | ||
| _ResultT = TypeVar("_ResultT", default=Any) |
Member
There was a problem hiding this comment.
we did not pin typing-extensions and it seems this use of TypeVar requires typing-extensions >= 4.4.0, we should probably pin it
| @wrap(async_result) | ||
| def create_completion(result: IAsyncResult) -> bool: | ||
| try: | ||
| return cast("bool", result.get()) |
Member
There was a problem hiding this comment.
Not really related to this PR but that might need a change? result.get() is not a bool in case of create_async()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why is this needed?
Kazoo's async methods return a bare
IAsyncResult, soget()becomesAnyand synchronous wrappers need casts. This makes the public annotations less useful.This is the first step toward typing the full request path. A follow-up can tie each wire request to its response with a generic
_submithelper, then carry that type through the pending queue.Proposed Changes
IAsyncResultgeneric in the value it carries.wait()returns as object.Does this PR introduce any breaking change?
No. Runtime APIs and behavior stay the same.