Skip to content

Commit 04464f8

Browse files
committed
Improve types in DPO driver
1 parent 2a1bfb2 commit 04464f8

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

src/qcodes/instrument_drivers/tektronix/DPO7200xx.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def __init__(
232232
"""
233233

234234

235-
class TektronixDPOWaveform(InstrumentChannel):
235+
class TektronixDPOWaveform(InstrumentChannel["TektronixDPOChannel"]):
236236
"""
237237
This submodule retrieves data from waveform sources, e.g.
238238
channels.
@@ -246,7 +246,7 @@ class TektronixDPOWaveform(InstrumentChannel):
246246

247247
def __init__(
248248
self,
249-
parent: InstrumentBase,
249+
parent: "TektronixDPOChannel",
250250
name: str,
251251
identifier: str,
252252
**kwargs: "Unpack[InstrumentBaseKWArgs]",
@@ -345,6 +345,12 @@ def __init__(
345345
)
346346
"""Parameter trace"""
347347

348+
@property
349+
def root_instrument(self) -> "TektronixDPO7000xx":
350+
root_instrument = super().root_instrument
351+
assert isinstance(root_instrument, TektronixDPO7000xx)
352+
return root_instrument
353+
348354
def _get_cmd(self, cmd_string: str) -> "Callable[[], str]":
349355
"""
350356
Parameters defined in this submodule require the correct
@@ -363,7 +369,7 @@ def _get_trace_data(self) -> npt.NDArray:
363369

364370
if not waveform.is_binary():
365371
raw_data = self.root_instrument.visa_handle.query_ascii_values(
366-
"CURVE?", container=np.array
372+
"CURVE?", container=np.ndarray
367373
)
368374
else:
369375
bytes_per_sample = waveform.bytes_per_sample()
@@ -378,7 +384,7 @@ def _get_trace_data(self) -> npt.NDArray:
378384
"CURVE?",
379385
datatype=data_type,
380386
is_big_endian=is_big_endian,
381-
container=np.array,
387+
container=np.ndarray,
382388
)
383389

384390
return (raw_data - self.raw_data_offset()) * self.scale() + self.offset()
@@ -430,7 +436,7 @@ def __init__(
430436
)
431437
"""Parameter is_big_endian"""
432438

433-
self.bytes_per_sample: Parameter = self.add_parameter(
439+
self.bytes_per_sample: Parameter[int, Self] = self.add_parameter(
434440
"bytes_per_sample",
435441
get_cmd="WFMOutpre:BYT_Nr?",
436442
set_cmd="WFMOutpre:BYT_Nr {}",
@@ -448,7 +454,7 @@ def __init__(
448454
"""Parameter is_binary"""
449455

450456

451-
class TektronixDPOChannel(InstrumentChannel):
457+
class TektronixDPOChannel(InstrumentChannel[TektronixDPO7000xx]):
452458
"""
453459
The main channel module for the oscilloscope. The parameters
454460
defined here reflect the waveforms as they are displayed on
@@ -457,7 +463,7 @@ class TektronixDPOChannel(InstrumentChannel):
457463

458464
def __init__(
459465
self,
460-
parent: Instrument | InstrumentChannel,
466+
parent: TektronixDPO7000xx,
461467
name: str,
462468
channel_number: int,
463469
**kwargs: "Unpack[InstrumentBaseKWArgs]",
@@ -546,23 +552,23 @@ def set_trace_length(self, value: int) -> None:
546552
value: The requested number of samples in the trace
547553
548554
"""
549-
if self.root_instrument.horizontal.record_length() < value:
555+
if self.parent.horizontal.record_length() < value:
550556
raise ValueError(
551557
"Cannot set a trace length which is larger than "
552558
"the record length. Please switch to manual mode "
553559
"and adjust the record length first"
554560
)
555561

556-
self.root_instrument.data.start_index(1)
557-
self.root_instrument.data.stop_index(value)
562+
self.parent.data.start_index(1)
563+
self.parent.data.stop_index(value)
558564

559565
def set_trace_time(self, value: float) -> None:
560566
"""
561567
Args:
562568
value: The time over which a trace is desired.
563569
564570
"""
565-
sample_rate = self.root_instrument.horizontal.sample_rate()
571+
sample_rate = self.parent.horizontal.sample_rate()
566572
required_sample_count = int(sample_rate * value)
567573
self.set_trace_length(required_sample_count)
568574

0 commit comments

Comments
 (0)