From 1906396f7433b269555848ff5b861a2a271f3e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saugat=20Pachhai=20=28=E0=A4=B8=E0=A5=8C=E0=A4=97=E0=A4=BE?= =?UTF-8?q?=E0=A4=A4=29?= Date: Wed, 10 Jan 2024 21:07:52 +0545 Subject: [PATCH] callbacks.branched: replace positional kwargs with arbitrary keyword arguments --- fsspec/callbacks.py | 8 ++++---- fsspec/spec.py | 4 ++-- fsspec/tests/test_callbacks.py | 6 ++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/fsspec/callbacks.py b/fsspec/callbacks.py index 5d34f4d19..646bc3eb1 100644 --- a/fsspec/callbacks.py +++ b/fsspec/callbacks.py @@ -37,7 +37,7 @@ def __exit__(self, *exc_args): def close(self): """Close callback.""" - def branched(self, path_1, path_2, kwargs): + def branched(self, path_1, path_2, **kwargs): """ Return callback for child transfers @@ -58,8 +58,8 @@ def branched(self, path_1, path_2, kwargs): Child's source path path_2: str Child's destination path - kwargs: dict - arguments passed to child method, e.g., put_file. + **kwargs: + Arbitrary keyword arguments Returns ------- @@ -77,7 +77,7 @@ def branch_coro(self, fn): @wraps(fn) async def func(path1, path2: str, **kwargs): - with self.branched(path1, path2, kwargs) as child: + with self.branched(path1, path2, **kwargs) as child: return await fn(path1, path2, callback=child, **kwargs) return func diff --git a/fsspec/spec.py b/fsspec/spec.py index cfe1f796d..2ba46ccaa 100644 --- a/fsspec/spec.py +++ b/fsspec/spec.py @@ -967,7 +967,7 @@ def get( callback.set_size(len(lpaths)) for lpath, rpath in callback.wrap(zip(lpaths, rpaths)): - with callback.branched(rpath, lpath, kwargs) as child: + with callback.branched(rpath, lpath) as child: self.get_file(rpath, lpath, callback=child, **kwargs) def put_file(self, lpath, rpath, callback=_DEFAULT_CALLBACK, **kwargs): @@ -1053,7 +1053,7 @@ def put( callback.set_size(len(rpaths)) for lpath, rpath in callback.wrap(zip(lpaths, rpaths)): - with callback.branched(lpath, rpath, kwargs) as child: + with callback.branched(lpath, rpath) as child: self.put_file(lpath, rpath, callback=child, **kwargs) def head(self, path, size=1024): diff --git a/fsspec/tests/test_callbacks.py b/fsspec/tests/test_callbacks.py index 0e064aad8..a74b053d2 100644 --- a/fsspec/tests/test_callbacks.py +++ b/fsspec/tests/test_callbacks.py @@ -37,13 +37,11 @@ def test_callbacks_as_context_manager(mocker): def test_callbacks_branched(): callback = Callback() - kwargs = {"key": "value"} - branch = callback.branched("path_1", "path_2", kwargs) + branch = callback.branched("path_1", "path_2") assert branch is not callback assert isinstance(branch, Callback) - assert kwargs == {"key": "value"} @pytest.mark.asyncio @@ -55,7 +53,7 @@ async def test_callbacks_branch_coro(mocker): assert await wrapped_fn("path_1", "path_2", key="value") == 10 - spy.assert_called_once_with("path_1", "path_2", {"key": "value"}) + spy.assert_called_once_with("path_1", "path_2", key="value") async_fn.assert_called_once_with( "path_1", "path_2", callback=spy.spy_return, key="value" )