Skip to content
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

use Iterable[T] instead of Sequence[T] in Pool.map iterable #212

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fabridamicelli
Copy link

@fabridamicelli fabridamicelli commented Jul 30, 2024

First off: Thank you very much for this package! :)

Here's a little thing about type hints I found.
In essence the Sequece type is too restrictive. The function map can deal as is with any iterable.

Description

The type of the arg iterable should be a Iterable instead of Sequence.
Here's pyright hint:

pyright-error

And here's after the fix

pyright-noerror

@fabridamicelli
Copy link
Author

Here's an actually running example code:

import asyncio

from aiomultiprocess import Pool


async def f(i: int) -> int:
    await asyncio.sleep(0.1)
    return i


async def main():
    async with Pool() as p:
        vals_seq = [0, 1, 2]
        vals_iter = (i for i in range(3))

        print(await p.map(f, vals_seq))
        print(await p.map(f, vals_iter))


if __name__ == "__main__":
    asyncio.run(main())

pyright-noerror

which outputs:

out

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.

1 participant