Skip to content

Commit b844333

Browse files
authored
fix(build): resolve mypyc signature generation error in portal.py (#296)
Fixes the mypyc build failure in v0.34.0 by refactoring the `call()` method signatures in `portal.py`.
1 parent dc89cfc commit b844333

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

sqlspec/utils/portal.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ async def _async_caller(
149149
result: _R = await func(*args, **kwargs)
150150
return result
151151

152-
def call(
153-
self, func: "Callable[..., Coroutine[Any, Any, _R]]", *args: Any, timeout: float = 300.0, **kwargs: Any
154-
) -> _R:
152+
def call(self, func: "Callable[..., Coroutine[Any, Any, _R]]", *args: Any, **kwargs: Any) -> _R:
155153
"""Call an async function from synchronous context.
156154
157155
Executes the async function in the background event loop and blocks
@@ -160,8 +158,7 @@ def call(
160158
Args:
161159
func: The async function to call.
162160
*args: Positional arguments to the function.
163-
timeout: Maximum seconds to wait for result (default 300).
164-
**kwargs: Keyword arguments to the function.
161+
**kwargs: Keyword arguments. Supports 'timeout' (float, default 300.0).
165162
166163
Returns:
167164
Result of the async function.
@@ -170,6 +167,7 @@ def call(
170167
ImproperConfigurationError: If portal provider not started or timeout reached.
171168
172169
"""
170+
timeout: float = float(kwargs.pop("timeout", 300.0))
173171
if self._loop is None or not self.is_running:
174172
msg = "Portal provider not running. Call start() first."
175173
raise ImproperConfigurationError(msg)
@@ -233,22 +231,19 @@ def __init__(self, provider: "PortalProvider") -> None:
233231
"""
234232
self._provider = provider
235233

236-
def call(
237-
self, func: "Callable[..., Coroutine[Any, Any, _R]]", *args: Any, timeout: float = 300.0, **kwargs: Any
238-
) -> _R:
234+
def call(self, func: "Callable[..., Coroutine[Any, Any, _R]]", *args: Any, **kwargs: Any) -> _R:
239235
"""Call an async function using the portal provider.
240236
241237
Args:
242238
func: The async function to call.
243239
*args: Positional arguments to the function.
244-
timeout: Maximum seconds to wait for result (default 300).
245-
**kwargs: Keyword arguments to the function.
240+
**kwargs: Keyword arguments. Supports 'timeout' (float, default 300.0).
246241
247242
Returns:
248243
Result of the async function.
249244
250245
"""
251-
return self._provider.call(func, *args, timeout=timeout, **kwargs)
246+
return self._provider.call(func, *args, **kwargs)
252247

253248

254249
class PortalManager(metaclass=SingletonMeta):

tests/integration/test_adapters/test_psqlpy/test_extensions/test_events_listen_notify.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def _handler(message: Any) -> None:
3636

3737
try:
3838
listener = channel.listen("alerts", _handler, poll_interval=0.2)
39-
await asyncio.sleep(0.1)
39+
await asyncio.sleep(0.3) # Allow listener to subscribe before publishing
4040
event_id = await channel.publish("alerts", {"action": "native"})
4141
for _ in range(200):
4242
if received:
@@ -82,7 +82,7 @@ async def _handler(message: Any) -> None:
8282

8383
try:
8484
listener = channel.listen("alerts", _handler, poll_interval=0.2)
85-
await asyncio.sleep(0.1)
85+
await asyncio.sleep(0.3) # Allow listener to subscribe before publishing
8686
event_id = await channel.publish("alerts", {"action": "hybrid"})
8787
for _ in range(200):
8888
if received:

tests/integration/test_adapters/test_psycopg/test_extensions/test_events_listen_notify.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def test_psycopg_sync_listen_notify(postgres_service: "Any") -> None:
3434

3535
received: list[Any] = []
3636
listener = channel.listen("alerts", lambda message: received.append(message), poll_interval=0.2)
37+
time.sleep(0.3) # Allow listener to subscribe before publishing
3738
event_id = channel.publish("alerts", {"action": "ping"})
3839
for _ in range(200):
3940
if received:
@@ -67,6 +68,7 @@ async def _handler(message: Any) -> None:
6768
received.append(message)
6869

6970
listener = channel.listen("alerts", _handler, poll_interval=0.2)
71+
await asyncio.sleep(0.3) # Allow listener to subscribe before publishing
7072
event_id = await channel.publish("alerts", {"action": "async"})
7173
for _ in range(200):
7274
if received:
@@ -101,6 +103,7 @@ def test_psycopg_sync_hybrid_listen_notify_durable(postgres_service: "Any", tmp_
101103

102104
received: list[Any] = []
103105
listener = channel.listen("alerts", lambda message: received.append(message), poll_interval=0.2)
106+
time.sleep(0.3) # Allow listener to subscribe before publishing
104107
event_id = channel.publish("alerts", {"action": "hybrid"})
105108
for _ in range(200):
106109
if received:
@@ -140,6 +143,7 @@ async def _handler(message: Any) -> None:
140143
received.append(message)
141144

142145
listener = channel.listen("alerts", _handler, poll_interval=0.2)
146+
await asyncio.sleep(0.3) # Allow listener to subscribe before publishing
143147
event_id = await channel.publish("alerts", {"action": "hybrid-async"})
144148
for _ in range(200):
145149
if received:

0 commit comments

Comments
 (0)