Skip to content

Commit 5029743

Browse files
committed
fix: fix mypy
1 parent 53ab37f commit 5029743

File tree

7 files changed

+37
-17
lines changed

7 files changed

+37
-17
lines changed

stream_chat/async_chat/channel_batch_updater.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import List
1+
import sys
2+
from typing import TYPE_CHECKING, List
23

34
from stream_chat.types.channel_batch import (
45
ChannelBatchMemberRequest,
@@ -8,13 +9,16 @@
89
)
910
from stream_chat.types.stream_response import StreamResponse
1011

12+
if TYPE_CHECKING:
13+
from stream_chat.async_chat.client import StreamChatAsync
14+
1115

1216
class ChannelBatchUpdater:
1317
"""
1418
Provides convenience methods for batch channel operations (async).
1519
"""
1620

17-
def __init__(self, client):
21+
def __init__(self, client: "StreamChatAsync") -> None:
1822
self.client = client
1923

2024
async def add_members(

stream_chat/async_chat/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
)
1919

2020
if TYPE_CHECKING:
21+
from stream_chat.async_chat.channel_batch_updater import ChannelBatchUpdater
2122
from stream_chat.types.channel_batch import ChannelsBatchOptions
2223
from urllib.parse import urlparse
2324

@@ -1033,7 +1034,7 @@ async def mark_delivered_simple(
10331034
return await self.mark_delivered(data)
10341035

10351036
async def update_channels_batch(
1036-
self, options: "ChannelsBatchOptions"
1037+
self, options: ChannelsBatchOptions
10371038
) -> StreamResponse:
10381039
"""
10391040
Updates channels in batch based on the provided options.
@@ -1046,7 +1047,7 @@ async def update_channels_batch(
10461047

10471048
return await self.put("channels/batch", data=options)
10481049

1049-
def channel_batch_updater(self) -> "ChannelBatchUpdater":
1050+
def channel_batch_updater(self) -> ChannelBatchUpdater:
10501051
"""
10511052
Returns a ChannelBatchUpdater instance for batch channel operations.
10521053

stream_chat/channel_batch_updater.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import List, Optional
1+
import sys
2+
from typing import TYPE_CHECKING, List, Optional
23

34
from stream_chat.types.channel_batch import (
45
ChannelBatchMemberRequest,
@@ -8,13 +9,16 @@
89
)
910
from stream_chat.types.stream_response import StreamResponse
1011

12+
if TYPE_CHECKING:
13+
from stream_chat.client import StreamChat
14+
1115

1216
class ChannelBatchUpdater:
1317
"""
1418
Provides convenience methods for batch channel operations.
1519
"""
1620

17-
def __init__(self, client):
21+
def __init__(self, client: "StreamChat") -> None:
1822
self.client = client
1923

2024
def add_members(

stream_chat/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from urllib.request import Request, urlopen
1818

1919
if TYPE_CHECKING:
20+
from stream_chat.channel_batch_updater import ChannelBatchUpdater
2021
from stream_chat.types.channel_batch import ChannelsBatchOptions
2122

2223
from stream_chat.campaign import Campaign
@@ -999,7 +1000,7 @@ def mark_delivered_simple(
9991000
}
10001001
return self.mark_delivered(data=data)
10011002

1002-
def update_channels_batch(self, options: "ChannelsBatchOptions") -> StreamResponse:
1003+
def update_channels_batch(self, options: ChannelsBatchOptions) -> StreamResponse:
10031004
"""
10041005
Updates channels in batch based on the provided options.
10051006
@@ -1011,7 +1012,7 @@ def update_channels_batch(self, options: "ChannelsBatchOptions") -> StreamRespon
10111012

10121013
return self.put("channels/batch", data=options)
10131014

1014-
def channel_batch_updater(self) -> "ChannelBatchUpdater":
1015+
def channel_batch_updater(self) -> ChannelBatchUpdater:
10151016
"""
10161017
Returns a ChannelBatchUpdater instance for batch channel operations.
10171018

stream_chat/tests/async_chat/test_channel_batch_updater.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,23 @@ async def test_channel_batch_updater_add_members(
9393
continue
9494

9595
if task["status"] == "completed":
96-
# Wait a bit and verify members were added
96+
# Wait a bit and verify members were added to both channels
9797
for _ in range(120):
9898
await asyncio.sleep(1)
9999
ch1_members = await ch1.query_members({})
100100
ch2_members = await ch2.query_members({})
101101

102102
ch1_member_ids = [m["user_id"] for m in ch1_members]
103-
all_found = all(
103+
ch2_member_ids = [m["user_id"] for m in ch2_members]
104+
all_found_ch1 = all(
104105
user_id in ch1_member_ids
105106
for user_id in [u["id"] for u in users_to_add]
106107
)
107-
if all_found:
108+
all_found_ch2 = all(
109+
user_id in ch2_member_ids
110+
for user_id in [u["id"] for u in users_to_add]
111+
)
112+
if all_found_ch1 and all_found_ch2:
108113
return
109114

110115
pytest.fail("changes not visible after 2 minutes")

stream_chat/tests/test_channel_batch_updater.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,23 @@ def test_channel_batch_updater_add_members(
9090
continue
9191

9292
if task["status"] == "completed":
93-
# Wait a bit and verify members were added
93+
# Wait a bit and verify members were added to both channels
9494
for _ in range(120):
9595
time.sleep(1)
9696
ch1_members = ch1.query_members({})
9797
ch2_members = ch2.query_members({})
9898

9999
ch1_member_ids = [m["user_id"] for m in ch1_members]
100-
all_found = all(
100+
ch2_member_ids = [m["user_id"] for m in ch2_members]
101+
all_found_ch1 = all(
101102
user_id in ch1_member_ids
102103
for user_id in [u["id"] for u in users_to_add]
103104
)
104-
if all_found:
105+
all_found_ch2 = all(
106+
user_id in ch2_member_ids
107+
for user_id in [u["id"] for u in users_to_add]
108+
)
109+
if all_found_ch1 and all_found_ch2:
105110
return
106111

107112
pytest.fail("changes not visible after 2 minutes")

stream_chat/types/channel_batch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ class ChannelsBatchFilters(TypedDict, total=False):
7474
filter_tags: Optional[Any]
7575

7676

77-
class ChannelsBatchOptions(TypedDict):
77+
class ChannelsBatchOptions(TypedDict, total=False):
7878
"""
7979
Represents options for batch channel updates.
8080
8181
Parameters:
82-
operation: The batch operation to perform.
83-
filter: The filter to match channels.
82+
operation: The batch operation to perform (required).
83+
filter: The filter to match channels (required).
8484
members: List of members for member-related operations (optional).
8585
data: Channel data updates for updateData operation (optional).
8686
filter_tags_update: List of filter tags for filter tag operations (optional).

0 commit comments

Comments
 (0)