Skip to content

Commit

Permalink
Update websocket_api.py
Browse files Browse the repository at this point in the history
"Enhance type hinting for 'connect' to improve IDE support"
  • Loading branch information
circansm committed Jun 10, 2024
1 parent 27a3468 commit 3a0950f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/solana/rpc/websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def _process_rpc_response(self, raw: str) -> List[Union[Notification, Subscripti
return cast(List[Union[Notification, SubscriptionResult]], parsed)


class connect(ws_connect): # pylint: disable=invalid-name,too-few-public-methods
class connect(ws_connect): # pylint: disable=invalid-name
"""Solana RPC websocket connector."""

def __init__(self, uri: str = "ws://localhost:8900", **kwargs: Any) -> None:
Expand All @@ -416,4 +416,11 @@ def __init__(self, uri: str = "ws://localhost:8900", **kwargs: Any) -> None:
uri: The websocket endpoint.
**kwargs: Keyword arguments for ``websockets.legacy.client.connect``
"""
super().__init__(uri, **kwargs, create_protocol=SolanaWsClientProtocol)
# Ensure that create_protocol explicitly creates a SolanaWsClientProtocol
kwargs.setdefault("create_protocol", SolanaWsClientProtocol)
super().__init__(uri, **kwargs)

async def __aenter__(self) -> SolanaWsClientProtocol:
"""Overrides to specify the type of protocol explicitly."""
protocol = await super().__aenter__()
return cast(SolanaWsClientProtocol, protocol)

0 comments on commit 3a0950f

Please sign in to comment.