From 44b442f5fb1976ff50e3fb5dbab08354b781f114 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 20 Aug 2025 13:08:32 +0100 Subject: [PATCH 1/2] Raise more helpful errors in _dereference_path --- src/zarr/storage/_common.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/zarr/storage/_common.py b/src/zarr/storage/_common.py index 3a63b30e9b..a673a85959 100644 --- a/src/zarr/storage/_common.py +++ b/src/zarr/storage/_common.py @@ -31,8 +31,12 @@ def _dereference_path(root: str, path: str) -> str: - assert isinstance(root, str) - assert isinstance(path, str) + if not isinstance(root, str): + msg = f"{root=} is not a string ({type(root)=})" + raise TypeError(msg) + if not isinstance(path, str): + msg = f"{path=} is not a string ({type(path)=})" + raise TypeError(msg) root = root.rstrip("/") path = f"{root}/{path}" if root else path return path.rstrip("/") From 254df583052203c5d0f0ece8a9e1bbed62d60f99 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 3 Sep 2025 19:36:47 +0100 Subject: [PATCH 2/2] Add some type ignore comments --- src/zarr/storage/_common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/zarr/storage/_common.py b/src/zarr/storage/_common.py index 29fb879f8e..177d84cd01 100644 --- a/src/zarr/storage/_common.py +++ b/src/zarr/storage/_common.py @@ -32,10 +32,10 @@ def _dereference_path(root: str, path: str) -> str: if not isinstance(root, str): - msg = f"{root=} is not a string ({type(root)=})" + msg = f"{root=} is not a string ({type(root)=})" # type: ignore[unreachable] raise TypeError(msg) if not isinstance(path, str): - msg = f"{path=} is not a string ({type(path)=})" + msg = f"{path=} is not a string ({type(path)=})" # type: ignore[unreachable] raise TypeError(msg) root = root.rstrip("/") path = f"{root}/{path}" if root else path