Skip to content

typing: propagate result types through async APIs - #797

Open
bringhurst wants to merge 1 commit into
python-zk:masterfrom
bringhurst:typing/generic-async-results
Open

typing: propagate result types through async APIs#797
bringhurst wants to merge 1 commit into
python-zk:masterfrom
bringhurst:typing/generic-async-results

Conversation

@bringhurst

Copy link
Copy Markdown
Contributor

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.

## 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

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.42%. Comparing base (e894342) to head (48738be).
⚠️ Report is 2 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ThosRTanner

Copy link
Copy Markdown
Contributor

That's nice! Takes something off my todo list as well!

Comment thread kazoo/interfaces.py


SpawnedFunc = Callable[..., None]
_ResultT = TypeVar("_ResultT", default=Any)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we did not pin typing-extensions and it seems this use of TypeVar requires typing-extensions >= 4.4.0, we should probably pin it

Comment thread kazoo/client.py
@wrap(async_result)
def create_completion(result: IAsyncResult) -> bool:
try:
return cast("bool", result.get())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not really related to this PR but that might need a change? result.get() is not a bool in case of create_async()

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.

3 participants