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

add ConnectOptions dataclass #610

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Conversation

swelborn
Copy link

To fix #600.

Let me know if this is an OK approach.

Docstring is incomplete, but not sure where you'd like to put that. I can also add/change some tests, but it would be great if you could point me in the right direction for where to add those (there are 4 test_client files...).

@swelborn swelborn changed the title add ConnectConfig dataclass add ConnectOptions dataclass Sep 24, 2024
@@ -419,6 +457,41 @@ async def subscribe_handler(msg):
asyncio.run(main())

"""

if config:
Copy link
Contributor

Choose a reason for hiding this comment

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

Bigger refactor but maybe merge into the config rather than out of it?

Copy link
Author

Choose a reason for hiding this comment

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

refactored in e668f54

@@ -1261,7 +1334,7 @@ async def _flush_pending(
except asyncio.CancelledError:
pass

def _setup_server_pool(self, connect_url: Union[List[str]]) -> None:
def _setup_server_pool(self, connect_url: Union[str, List[str]]) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Intentional change?

Copy link
Author

Choose a reason for hiding this comment

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

Yes this throws a typing error -- Union[List[str]] is just List[str], and _setup_server_pool accepts both str and List[str] (via isinstance(...).

It is not exactly related, but is in the connect call and should be fixed... do you think it belongs in a separate PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, just checking. I'm doing a lint fix PR so that should take care of it. Can just leave it in for now.

this inspects call signature at runtime to prevent an ugly block of if/else to merge kwargs into config
@swelborn
Copy link
Author

I tried something out with merging. Let me know if this approach will work. It looks at the call signature on every connect() call, so that's not ideal but I don't imagine it would cost a significant performance hit.

@caspervonb
Copy link
Contributor

I tried something out with merging. Let me know if this approach will work. It looks at the call signature on every connect() call, so that's not ideal but I don't imagine it would cost a significant performance hit.

Yeah not worried about connect having overhead. Mostly the hot paths (e.g io where we have to be particularly careful).

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.

nc.connect() API
2 participants