Just a concept of gather-like method#1966
Just a concept of gather-like method#1966RomanMIzulin wants to merge 11 commits intodry-python:masterfrom
Conversation
returns/methods/gather.py
Outdated
|
|
||
| async with anyio.create_task_group() as tg: | ||
| containers_t = tuple(containers) | ||
| results: list[IOResult] = len(containers_t)*[IOResult(None)] |
There was a problem hiding this comment.
you can use a dict[int, IOResult[R, E]] here instead. Where int is the index of the running task.
returns/methods/gather.py
Outdated
|
|
||
| for i, coro in enumerate(containers_t): | ||
| tg.start_soon(run_task, coro, i) | ||
| return tuple(results) |
There was a problem hiding this comment.
and return a tuple sorted by keys of the this dict.
tests/test_methods/test_gather.py
Outdated
| ]) | ||
| def test_gather(containers, expected): | ||
| """Test partition function.""" | ||
| assert gather(containers) == expected |
There was a problem hiding this comment.
This should not be possible. You cannot mix Future and FutureResult in one operation without an explicit cast.
There was a problem hiding this comment.
(from mypy's point of view, I mean)
There was a problem hiding this comment.
It is not supposed to mix IO operations that can and can not fail? Or it is just mypy limitation?
returns/methods/__init__.py
Outdated
| @@ -1,4 +1,5 @@ | |||
| from returns.methods.cond import cond as cond | |||
| from returns.methods.gather import gather as gather | |||
There was a problem hiding this comment.
Let's create a new file: async_.py and put it there.
There was a problem hiding this comment.
Is naming of the method good(gather)?
Co-authored-by: sobolevn <mail@sobolevn.me>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1966 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 80 82 +2
Lines 2485 2592 +107
Branches 437 45 -392
==========================================
+ Hits 2485 2592 +107 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Before processing further, here a little snippet how it could look like.
CHANGELOG.md🙏 Please, if you or your company finds
dry-pythonvaluable, help us sustain the project by sponsoring it transparently on https://github.com/sponsors/dry-python. As a thank you, your profile/company logo will be added to our main README which receives hundreds of unique visitors per day.