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

What is the correct way to type annotate a janus.Queue? #372

Closed
rbuffat opened this issue Nov 3, 2021 · 3 comments
Closed

What is the correct way to type annotate a janus.Queue? #372

rbuffat opened this issue Nov 3, 2021 · 3 comments

Comments

@rbuffat
Copy link
Contributor

rbuffat commented Nov 3, 2021

When I try to add type hints to the example, pylance creates reportPrivateUsage warnings.

import asyncio
import janus


def threaded(sync_q: janus._SyncQueueProxy[int]):
    for i in range(100):
        sync_q.put(i)
    sync_q.join()


async def async_coro(async_q: janus._AsyncQueueProxy[int]):
    for i in range(100):
        val = await async_q.get()
        assert val == i
        async_q.task_done()


async def main():
    queue: janus.Queue[int] = janus.Queue()
    loop = asyncio.get_running_loop()
    fut = loop.run_in_executor(None, threaded, queue.sync_q)
    await async_coro(queue.async_q)
    await fut
    queue.close()
    await queue.wait_closed()


asyncio.run(main())

Warnings:

"_SyncQueueProxy" is private and used outside of the module in which it is declared

"_AsyncQueueProxy" is private and used outside of the module in which it is declared

What is the preferred way to add type hints to janus Queues?

@asvetlov
Copy link
Member

asvetlov commented Nov 3, 2021

Good question!

Perhaphs we should make both classes public but forbid their instantiation by user code.

I can imagine something like NoPublicConstructor approach

Would you make a pull request?

@rbuffat
Copy link
Contributor Author

rbuffat commented Nov 4, 2021

I will give it a shot, but I probably need some time to get familiar with it.

@asvetlov
Copy link
Member

Fixed by #374

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

No branches or pull requests

2 participants