Skip to content

Commit 563b194

Browse files
committed
chore(ruff): Parametrize ObjectDoesNotExist
1 parent 363121c commit 563b194

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
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

+4-2
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,10 @@ def fetch_obj(
241241

242242
if obj is None:
243243
raise ObjectDoesNotExist(
244-
f"Could not find {obj_key}={obj_id} for {list_cmd} "
245-
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,
246248
)
247249

248250
assert obj is not None

0 commit comments

Comments
 (0)