Skip to content

Commit a0a5be8

Browse files
committed
Chore: type hint + docstring _samples_dict and _samples_list; use _RpcBase._call to be safe
1 parent fed1030 commit a0a5be8

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

python/twinleaf/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def _instantiate_rpcs_recursive(self, parent, prefix=''):
5858
setattr(parent, attr_name, child)
5959
self._instantiate_rpcs_recursive(child, full_path)
6060

61-
def _samples_dict(self, n: int = 1, stream: str = "", columns: list[str] | None=None):
61+
def _samples_dict(self, n: int = 1, stream: str = "", columns: list[str] | None=None) -> dict[int, dict[str, list[int | float]]]:
62+
""" Parse underlying sample iterator into dict """
6263
if columns is None: columns = [] # Avoid mutable default
6364
samples = list(self._samples(n, stream=stream, columns=columns))
6465
# Bin into streams
@@ -73,7 +74,8 @@ def _samples_dict(self, n: int = 1, stream: str = "", columns: list[str] | None=
7374
streams[stream_id][key].append(value)
7475
return streams
7576

76-
def _samples_list(self, n: int = 1, stream: str = "", columns: list[str] | None=None, time_column = True, title_row = True):
77+
def _samples_list(self, n: int = 1, stream: str = "", columns: list[str] | None=None, time_column = True, title_row = True) -> list[list[str | int | float]]:
78+
""" Parse underlying sample iterator into tabular array """
7779
if columns is None: columns = [] # Avoid mutable default
7880
streams = self._samples_dict(n, stream, columns)
7981
# Convert to list with rows of data. Not super happy about how inefficient this is.
@@ -161,7 +163,7 @@ def _survey(self) -> dict[str, _rpc_type]:
161163
# Check if it's an RPC that should be read
162164
if isinstance(attr, _RpcBase):
163165
if attr._data_type not in { None, bytes }:
164-
results[attr.__name__] = attr()
166+
results[attr.__name__] = attr._call()
165167

166168
# Recursively survey children (works for both Rpc and Survey)
167169
results |= attr._survey()

0 commit comments

Comments
 (0)