Skip to content

Commit 99eb153

Browse files
Mike ProsserMike Prosser
authored andcommitted
cleanup
1 parent ffeb341 commit 99eb153

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

protos/ni/pythonpanel/v1/python_panel_service.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ service PythonPanelService {
3535
// Enumerate the panels available in the system, including information about the state of the panels and what values they have.
3636
// Status Codes for errors:
3737
rpc EnumeratePanels(EnumeratePanelsRequest) returns (EnumeratePanelsResponse);
38-
38+
3939
// Get a value for a control on the panel
4040
// Status Codes for errors:
4141
// - INVALID_ARGUMENT:

src/nipanel/_panel_client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,22 @@ def get_value(self, panel_id: str, value_id: str) -> object:
130130
response = self._invoke_with_retry(self._get_stub().GetValue, try_get_value_request)
131131
return from_any(response.value)
132132

133-
def try_get_value(self, panel_id: str, value_id: str) -> tuple[bool, object]:
133+
def try_get_value(self, panel_id: str, value_id: str) -> object:
134134
"""Try to get the value for the control with value_id.
135135
136136
Args:
137137
panel_id: The ID of the panel.
138138
value_id: The ID of the control.
139139
140140
Returns:
141-
A tuple containing a boolean indicating whether the value was successfully retrieved and
142-
the value itself (or None if not present).
141+
The value if found, otherwise None.
143142
"""
144143
try_get_value_request = GetValueRequest(panel_id=panel_id, value_id=value_id)
145144
response = self._invoke_with_retry(self._get_stub().TryGetValue, try_get_value_request)
146145
if response.HasField("value"):
147-
return True, from_any(response.value)
146+
return from_any(response.value)
148147
else:
149-
return False, None
148+
return None
150149

151150
def _get_stub(self) -> PythonPanelServiceStub:
152151
if self._stub is None:

src/nipanel/_panel_value_accessor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def get_value(self, value_id: str, default_value: _T | None = None) -> _T | obje
7171
Returns:
7272
The value, or the default value if not set
7373
"""
74-
found, value = self._panel_client.try_get_value(self._panel_id, value_id)
75-
if not found:
74+
value = self._panel_client.try_get_value(self._panel_id, value_id)
75+
if value is None:
7676
if default_value is not None:
7777
return default_value
7878
raise KeyError(f"Value with id '{value_id}' not found on panel '{self._panel_id}'.")

tests/unit/test_convert.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ def test___python_panel_collection___to_any___valid_paneltype_value(
144144
assert unpack_dest.values == expected_value
145145

146146

147+
def test___none_value___to_any___raises_type_error() -> None:
148+
"""Test that passing None to to_any() raises a TypeError."""
149+
with pytest.raises(TypeError):
150+
nipanel._convert.to_any(None)
151+
152+
147153
# ========================================================
148154
# Built-in Types: Protobuf to Python
149155
# ========================================================

tests/unit/test_panel_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ def test___get_unset_value___raises_exception(fake_panel_channel: grpc.Channel)
6060
assert exc_info.value.code() == grpc.StatusCode.NOT_FOUND
6161

6262

63-
def test___try_get_unset_value___returns_not_found(fake_panel_channel: grpc.Channel) -> None:
63+
def test___try_get_unset_value___returns_none(fake_panel_channel: grpc.Channel) -> None:
6464
client = create_panel_client(fake_panel_channel)
6565

6666
response = client.try_get_value("panel1", "unset_id")
6767

68-
assert response == (False, None)
68+
assert response is None
6969

7070

7171
def test___set_value___enumerate_panels_shows_value(
@@ -83,7 +83,7 @@ def test___set_value___gets_value(fake_panel_channel: grpc.Channel) -> None:
8383

8484
client.set_value("panel1", "val1", "value1", notify=False)
8585

86-
assert client.try_get_value("panel1", "val1") == (True, "value1")
86+
assert client.try_get_value("panel1", "val1") == "value1"
8787

8888

8989
def create_panel_client(fake_panel_channel: grpc.Channel) -> PanelClient:

0 commit comments

Comments
 (0)