Skip to content
Open
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
18 changes: 5 additions & 13 deletions distributed/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,11 @@ def _raise(*args, **kwargs):

@functools.cache
def _expects_comm(func: Callable) -> bool:
sig = inspect.signature(func)
params = list(sig.parameters)
if params and params[0] == "comm":
return True
if params and params[0] == "stream":
warnings.warn(
"Calling the first argument of a RPC handler `stream` is "
"deprecated. Defining this argument is optional. Either remove the "
f"argument or rename it to `comm` in {func}.",
FutureWarning,
)
return True
return False
"""Return True if func expects a first argument named 'comm';
False otherwise.
"""
params = inspect.signature(func).parameters
return bool(params) and next(iter(params)) == "comm"


class Server:
Expand Down
14 changes: 0 additions & 14 deletions distributed/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,41 +1253,27 @@ def one_arg(self, arg): ...

def comm_arg(self, comm): ...

def stream_arg(self, stream): ...

def two_arg(self, arg, other): ...

def comm_arg_other(self, comm, other): ...

def stream_arg_other(self, stream, other): ...

def arg_kwarg(self, arg, other=None): ...

def comm_posarg_only(self, comm, /, other): ...

def comm_not_leading_position(self, other, comm): ...

def stream_not_leading_position(self, other, stream): ...

expected_warning = "first argument of a RPC handler `stream` is deprecated"

instance = A()

assert not _expects_comm(instance.empty)
assert not _expects_comm(instance.one_arg)
assert _expects_comm(instance.comm_arg)
with pytest.warns(FutureWarning, match=expected_warning):
assert _expects_comm(instance.stream_arg)
assert not _expects_comm(instance.two_arg)
assert _expects_comm(instance.comm_arg_other)
with pytest.warns(FutureWarning, match=expected_warning):
assert _expects_comm(instance.stream_arg_other)
assert not _expects_comm(instance.arg_kwarg)
assert _expects_comm(instance.comm_posarg_only)
assert not _expects_comm(instance.comm_not_leading_position)

assert not _expects_comm(instance.stream_not_leading_position)


class AsyncStopTCPListener(TCPListener):
async def stop(self):
Expand Down
Loading