Skip to content

Commit e218d45

Browse files
committed
gateway_base: replace -> object return types to -> Any
While `object` is type-safe, it is somewhat hostile to users (forces isinstance checks), so the common practice is to return `Any` in these cases.
1 parent 4d75439 commit e218d45

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/execnet/gateway_base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ def send(self, item: object) -> None:
911911
raise OSError(f"cannot send to {self!r}")
912912
self.gateway._send(Message.CHANNEL_DATA, self.id, dumps_internal(item))
913913

914-
def receive(self, timeout: float | None = None) -> object:
914+
def receive(self, timeout: float | None = None) -> Any:
915915
"""Receive a data item that was sent from the other side.
916916
917917
timeout: None [default] blocked waiting. A positive number
@@ -935,10 +935,10 @@ def receive(self, timeout: float | None = None) -> object:
935935
else:
936936
return x
937937

938-
def __iter__(self) -> Iterator[object]:
938+
def __iter__(self) -> Iterator[Any]:
939939
return self
940940

941-
def next(self) -> object:
941+
def next(self) -> Any:
942942
try:
943943
return self.receive()
944944
except EOFError:
@@ -1403,7 +1403,7 @@ def __init__(
14031403
else:
14041404
self.channelfactory = gw._channelfactory
14051405

1406-
def load(self, versioned: bool = False) -> object:
1406+
def load(self, versioned: bool = False) -> Any:
14071407
if versioned:
14081408
ver = self.stream.read(1)
14091409
if ver != DUMPFORMAT_VERSION:
@@ -1587,7 +1587,7 @@ def dump(byteio, obj: object) -> None:
15871587

15881588
def loads(
15891589
bytestring: bytes, py2str_as_py3str: bool = False, py3str_as_py2str: bool = False
1590-
) -> object:
1590+
) -> Any:
15911591
"""Deserialize the given bytestring to an object.
15921592
15931593
py2str_as_py3str: If true then string (str) objects previously
@@ -1609,7 +1609,7 @@ def loads(
16091609

16101610
def load(
16111611
io: ReadIO, py2str_as_py3str: bool = False, py3str_as_py2str: bool = False
1612-
) -> object:
1612+
) -> Any:
16131613
"""Derserialize an object form the specified stream.
16141614
16151615
Behaviour and parameters are otherwise the same as with ``loads``
@@ -1622,7 +1622,7 @@ def loads_internal(
16221622
bytestring: bytes,
16231623
channelfactory=None,
16241624
strconfig: tuple[bool, bool] | None = None,
1625-
) -> object:
1625+
) -> Any:
16261626
io = BytesIO(bytestring)
16271627
return Unserializer(io, channelfactory, strconfig).load()
16281628

src/execnet/multi.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from functools import partial
1212
from threading import Lock
1313
from typing import TYPE_CHECKING
14+
from typing import Any
1415
from typing import Callable
1516
from typing import Iterable
1617
from typing import Iterator
@@ -277,16 +278,16 @@ def send_each(self, item: object) -> None:
277278
ch.send(item)
278279

279280
@overload
280-
def receive_each(self, withchannel: Literal[False] = ...) -> list[object]:
281+
def receive_each(self, withchannel: Literal[False] = ...) -> list[Any]:
281282
pass
282283

283284
@overload
284-
def receive_each(self, withchannel: Literal[True]) -> list[tuple[Channel, object]]:
285+
def receive_each(self, withchannel: Literal[True]) -> list[tuple[Channel, Any]]:
285286
pass
286287

287288
def receive_each(
288289
self, withchannel: bool = False
289-
) -> list[tuple[Channel, object]] | list[object]:
290+
) -> list[tuple[Channel, Any]] | list[Any]:
290291
assert not hasattr(self, "_queue")
291292
l: list[object] = []
292293
for ch in self._channels:

0 commit comments

Comments
 (0)