Skip to content

Commit 8686990

Browse files
committed
Add new method to get channels in a type safe way
1 parent 00c66c0 commit 8686990

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/qcodes/instrument/channel.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,26 @@ def count( # pyright: ignore[reportIncompatibleMethodOverride]
338338
"""
339339
return self._channels.count(obj)
340340

341+
def get_channels_by_name(self: Self, *names: str) -> Self:
342+
"""
343+
Get a a ChannelTuple that only contains the selected names.
344+
345+
Args:
346+
*names: channel names
347+
348+
"""
349+
if len(names) == 0:
350+
raise Exception("one or more names must be given")
351+
selected_channels = tuple(self._channel_mapping[name] for name in names)
352+
return type(self)(
353+
self._parent,
354+
self._name,
355+
self._chan_type,
356+
selected_channels,
357+
self._snapshotable,
358+
self._paramclass,
359+
)
360+
341361
def get_channel_by_name(self: Self, *names: str) -> InstrumentModuleType | Self:
342362
"""
343363
Get a channel by name, or a ChannelTuple if multiple names are given.
@@ -350,6 +370,11 @@ def get_channel_by_name(self: Self, *names: str) -> InstrumentModuleType | Self:
350370
raise Exception("one or more names must be given")
351371
if len(names) == 1:
352372
return self._channel_mapping[names[0]]
373+
374+
raise Warning(
375+
"Supplying more than one name to get_channel_by_name is deprecated, use get_channels_by_name instead"
376+
)
377+
353378
selected_channels = tuple(self._channel_mapping[name] for name in names)
354379
return type(self)(
355380
self._parent,

0 commit comments

Comments
 (0)