From 4a10bc581f99c402d0bce85c5bb4107eee8baa20 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Mon, 30 Sep 2024 14:27:14 -0300 Subject: [PATCH] fix: mutable arguments --- realtime/_async/channel.py | 8 ++++---- realtime/_async/client.py | 8 ++++---- realtime/_async/push.py | 4 ++-- realtime/_sync/channel.py | 4 ++-- realtime/_sync/client.py | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/realtime/_async/channel.py b/realtime/_async/channel.py index b39ddbd..9814926 100644 --- a/realtime/_async/channel.py +++ b/realtime/_async/channel.py @@ -42,7 +42,7 @@ def __init__( self, socket: AsyncRealtimeClient, topic: str, - params: RealtimeChannelOptions = {"config": {}}, + params: Optional[RealtimeChannelOptions] = None, ) -> None: """ Initialize the Channel object. @@ -52,7 +52,7 @@ def __init__( :param params: Optional parameters for connection. """ self.socket = socket - self.params = params + self.params = params or {} self.topic = topic self._joined_once = False self.bindings: Dict[str, List[Binding]] = {} @@ -306,7 +306,7 @@ async def join(self) -> AsyncRealtimeChannel: # Event handling methods def _on( - self, type: str, callback: Callback, filter: Dict[str, Any] = {} + self, type: str, callback: Callback, filter: Optional[Dict[str, Any]] = None ) -> AsyncRealtimeChannel: """ Set up a listener for a specific event. @@ -318,7 +318,7 @@ def _on( """ type_lowercase = type.lower() - binding = Binding(type=type_lowercase, filter=filter, callback=callback) + binding = Binding(type=type_lowercase, filter=filter or {}, callback=callback) self.bindings.setdefault(type_lowercase, []).append(binding) return self diff --git a/realtime/_async/client.py b/realtime/_async/client.py index ae99b6e..1c3e538 100644 --- a/realtime/_async/client.py +++ b/realtime/_async/client.py @@ -39,8 +39,8 @@ def __init__( self, url: str, token: str, - auto_reconnect: bool = False, - params: Dict[str, Any] = {}, + auto_reconnect: bool = True, + params: Optional[Dict[str, Any]] = None, hb_interval: int = 30, max_retries: int = 5, initial_backoff: float = 1.0, @@ -60,7 +60,7 @@ def __init__( self.url = f"{re.sub(r'https://', 'wss://', re.sub(r'http://', 'ws://', url, flags=re.IGNORECASE), flags=re.IGNORECASE)}/websocket?apikey={token}" self.http_endpoint = http_endpoint_url(url) self.is_connected = False - self.params = params + self.params = params or {} self.apikey = token self.access_token = token self.send_buffer: List[Callable] = [] @@ -197,7 +197,7 @@ async def _heartbeat(self) -> None: @ensure_connection def channel( - self, topic: str, params: RealtimeChannelOptions = {} + self, topic: str, params: Optional[RealtimeChannelOptions] = None ) -> AsyncRealtimeChannel: """ :param topic: Initializes a channel and creates a two-way association with the socket diff --git a/realtime/_async/push.py b/realtime/_async/push.py index 06c62fb..8e7a68f 100644 --- a/realtime/_async/push.py +++ b/realtime/_async/push.py @@ -15,12 +15,12 @@ def __init__( self, channel: "AsyncRealtimeChannel", event: str, - payload: Dict[str, Any] = {}, + payload: Optional[Dict[str, Any]] = None, timeout: int = DEFAULT_TIMEOUT, ): self.channel = channel self.event = event - self.payload = payload + self.payload = payload or {} self.timeout = timeout self.rec_hooks: List[_Hook] = [] self.ref: Optional[str] = None diff --git a/realtime/_sync/channel.py b/realtime/_sync/channel.py index 4c42a3f..3512f9b 100644 --- a/realtime/_sync/channel.py +++ b/realtime/_sync/channel.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Optional from realtime.types import RealtimeChannelOptions @@ -19,7 +19,7 @@ def __init__( self, socket: SyncRealtimeClient, topic: str, - params: RealtimeChannelOptions = {"config": {}}, + params: Optional[RealtimeChannelOptions] = None, ) -> None: """ Initialize the Channel object. diff --git a/realtime/_sync/client.py b/realtime/_sync/client.py index 79995af..f4fbc4d 100644 --- a/realtime/_sync/client.py +++ b/realtime/_sync/client.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Union +from typing import Any, Dict, List, Optional, Union from .channel import RealtimeChannelOptions, SyncRealtimeChannel @@ -10,8 +10,8 @@ def __init__( self, url: str, token: str, - auto_reconnect: bool = False, - params: Dict[str, Any] = {}, + auto_reconnect: bool = True, + params: Optional[Dict[str, Any]] = None, hb_interval: int = 30, max_retries: int = 5, initial_backoff: float = 1.0, @@ -30,7 +30,7 @@ def __init__( """ def channel( - self, topic: str, params: RealtimeChannelOptions = {} + self, topic: str, params: Optional[RealtimeChannelOptions] = None ) -> SyncRealtimeChannel: """ :param topic: Initializes a channel and creates a two-way association with the socket