Skip to content

Commit 45270c1

Browse files
committed
chore(ruff): Parametrize ObjectDoesNotExist
1 parent a618868 commit 45270c1

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/libtmux/_internal/query_list.py

+17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
if TYPE_CHECKING:
1414
from typing_extensions import Protocol
1515

16+
from libtmux.neo import ListExtraArgs
17+
1618
class LookupProtocol(Protocol):
1719
"""Protocol for :class:`QueryList` filtering operators."""
1820

@@ -37,6 +39,21 @@ class MultipleObjectsReturned(Exception):
3739
class ObjectDoesNotExist(Exception):
3840
"""The query returned multiple objects when only one was expected."""
3941

42+
def __init__(
43+
self,
44+
obj_key: Optional[str] = None,
45+
obj_id: Optional[str] = None,
46+
list_cmd: Optional[str] = None,
47+
list_extra_args: "Optional[ListExtraArgs]" = None,
48+
*args: object,
49+
):
50+
if all(arg is not None for arg in [obj_key, obj_id, list_cmd, list_extra_args]):
51+
return super().__init__(
52+
f"Could not find {obj_key}={obj_id} for {list_cmd} "
53+
f'{list_extra_args if list_extra_args is not None else ""}'
54+
)
55+
return super().__init__("Could not find object")
56+
4057

4158
def keygetter(
4259
obj: "Mapping[str, Any]",

src/libtmux/neo.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ def _refresh(
179179

180180

181181
def fetch_objs(
182-
server: "Server", list_cmd: "ListCmd", list_extra_args: "t.Optional[ListExtraArgs]" = None
182+
server: "Server",
183+
list_cmd: "ListCmd",
184+
list_extra_args: "t.Optional[ListExtraArgs]" = None,
183185
) -> OutputsRaw:
184186
formats = list(Obj.__dataclass_fields__.keys())
185187

@@ -239,8 +241,10 @@ def fetch_obj(
239241

240242
if obj is None:
241243
raise ObjectDoesNotExist(
242-
f"Could not find {obj_key}={obj_id} for {list_cmd} "
243-
f'{list_extra_args if list_extra_args is not None else ""}'
244+
obj_key=obj_key,
245+
obj_id=obj_id,
246+
list_cmd=list_cmd,
247+
list_extra_args=list_extra_args,
244248
)
245249

246250
assert obj is not None

0 commit comments

Comments
 (0)