Skip to content

fix: narrow future() and future_safe() param types from Coroutine to Awaitable (#2404)#2456

Open
fazalpsinfo-cmyk wants to merge 1 commit into
dry-python:masterfrom
fazalpsinfo-cmyk:fix/awaitable-type-narrow
Open

fix: narrow future() and future_safe() param types from Coroutine to Awaitable (#2404)#2456
fazalpsinfo-cmyk wants to merge 1 commit into
dry-python:masterfrom
fazalpsinfo-cmyk:fix/awaitable-type-narrow

Conversation

@fazalpsinfo-cmyk

Copy link
Copy Markdown

future() and future_safe() currently require their decorated function to return Coroutine[SendType, ReturnType, YieldType], but they only await the result — they never use send() or throw(). This means valid async functions that return other Awaitable types (e.g. asyncio.Task, wrapped coroutines) are rejected by type checkers.

Fix: Changed the parameter type from Coroutine[_FirstType, _SecondType, _ValueType_co] to Awaitable[_ValueType_co] in all future() and future_safe() signatures (both overloads and implementation). Removed the now-unused _SecondType TypeVar.

Closes: #2404


If you find this useful, consider supporting my work: https://buymeacoffee.com/muhamedfazalps

…Awaitable (dry-python#2404)

future() and future_safe() only await the callable result — they do
not use send() or throw(). Changing the parameter type from
Coroutine[SendType, ReturnType, YieldType] to Awaitable[YieldType]
accepts a broader range of awaitables (asyncio Tasks, wrapped
coroutines, etc.) without losing type safety.

Removed unused _SecondType TypeVar.

Fixes dry-python#2404

@sobolevn sobolevn left a comment

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.

Please, add a test case.

@codspeed-hq

codspeed-hq Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 22 untouched benchmarks


Comparing fazalpsinfo-cmyk:fix/awaitable-type-narrow (3e48c4b) with master (96b68de)

Open in CodSpeed

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (82ef3ef) to head (3e48c4b).
⚠️ Report is 558 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##            master     #2456    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           80        81     +1     
  Lines         2485      2564    +79     
  Branches       437        44   -393     
==========================================
+ Hits          2485      2564    +79     

☔ 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.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants