|
10 | 10 | import uuid
|
11 | 11 | from collections.abc import Iterable, Iterator, Mapping
|
12 | 12 | from types import TracebackType
|
13 |
| -from typing import Any |
| 13 | +from typing import Any, Literal, overload |
14 | 14 |
|
15 | 15 | from ..exceptions import (
|
16 | 16 | ConcurrencyError,
|
@@ -241,6 +241,28 @@ def __iter__(self) -> Iterator[Data]:
|
241 | 241 | except ConnectionClosedOK:
|
242 | 242 | return
|
243 | 243 |
|
| 244 | + # This overload structure is required to avoid the error: |
| 245 | + # "parameter without a default follows parameter with a default" |
| 246 | + |
| 247 | + @overload |
| 248 | + def recv(self, timeout: float | None, decode: Literal[True]) -> str: ... |
| 249 | + |
| 250 | + @overload |
| 251 | + def recv(self, timeout: float | None, decode: Literal[False]) -> bytes: ... |
| 252 | + |
| 253 | + @overload |
| 254 | + def recv(self, timeout: float | None = None, *, decode: Literal[True]) -> str: ... |
| 255 | + |
| 256 | + @overload |
| 257 | + def recv( |
| 258 | + self, timeout: float | None = None, *, decode: Literal[False] |
| 259 | + ) -> bytes: ... |
| 260 | + |
| 261 | + @overload |
| 262 | + def recv( |
| 263 | + self, timeout: float | None = None, decode: bool | None = None |
| 264 | + ) -> Data: ... |
| 265 | + |
244 | 266 | def recv(self, timeout: float | None = None, decode: bool | None = None) -> Data:
|
245 | 267 | """
|
246 | 268 | Receive the next message.
|
@@ -311,6 +333,15 @@ def recv(self, timeout: float | None = None, decode: bool | None = None) -> Data
|
311 | 333 | self.recv_events_thread.join()
|
312 | 334 | raise self.protocol.close_exc from self.recv_exc
|
313 | 335 |
|
| 336 | + @overload |
| 337 | + def recv_streaming(self, decode: Literal[True]) -> Iterator[str]: ... |
| 338 | + |
| 339 | + @overload |
| 340 | + def recv_streaming(self, decode: Literal[False]) -> Iterator[bytes]: ... |
| 341 | + |
| 342 | + @overload |
| 343 | + def recv_streaming(self, decode: bool | None = None) -> Iterator[Data]: ... |
| 344 | + |
314 | 345 | def recv_streaming(self, decode: bool | None = None) -> Iterator[Data]:
|
315 | 346 | """
|
316 | 347 | Receive the next message frame by frame.
|
|
0 commit comments