Skip to content

Commit

Permalink
fix: mutable arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Sep 30, 2024
1 parent 0260de4 commit 4a10bc5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions realtime/_async/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(
self,
socket: AsyncRealtimeClient,
topic: str,
params: RealtimeChannelOptions = {"config": {}},
params: Optional[RealtimeChannelOptions] = None,
) -> None:
"""
Initialize the Channel object.
Expand All @@ -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]] = {}
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions realtime/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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] = []
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions realtime/_async/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions realtime/_sync/channel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional

from realtime.types import RealtimeChannelOptions

Expand All @@ -19,7 +19,7 @@ def __init__(
self,
socket: SyncRealtimeClient,
topic: str,
params: RealtimeChannelOptions = {"config": {}},
params: Optional[RealtimeChannelOptions] = None,
) -> None:
"""
Initialize the Channel object.
Expand Down
8 changes: 4 additions & 4 deletions realtime/_sync/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Union
from typing import Any, Dict, List, Optional, Union

from .channel import RealtimeChannelOptions, SyncRealtimeChannel

Expand All @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 4a10bc5

Please sign in to comment.