Skip to content

fix: default mutable arguments #216

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

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 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,20 +52,20 @@ def __init__(
:param params: Optional parameters for connection.
"""
self.socket = socket
self.params = params
self.params = params or RealtimeChannelOptions(
config={
"broadcast": {"ack": False, "self": False},
"presence": {"key": ""},
"private": False,
}
)
self.topic = topic
self._joined_once = False
self.bindings: Dict[str, List[Binding]] = {}
self.presence = AsyncRealtimePresence(self)
self.state = ChannelStates.CLOSED
self._push_buffer: List[AsyncPush] = []
self.timeout = self.socket.timeout
self.params["config"] = {
"broadcast": {"ack": False, "self": False},
"presence": {"key": ""},
"private": False,
**params.get("config", {}),
}

self.join_push = AsyncPush(self, ChannelEvents.join, self.params)
self.rejoin_timer = AsyncTimer(
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
6 changes: 3 additions & 3 deletions realtime/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading