|
8 | 8 |
|
9 | 9 | import warnings |
10 | 10 | from time import perf_counter |
11 | | -from typing import TYPE_CHECKING, Any, ClassVar, Literal |
| 11 | +from typing import TYPE_CHECKING, Any, ClassVar, Generic, Literal |
12 | 12 |
|
| 13 | +from qcodes.parameters.parameter_base import InstrumentTypeVar_co |
13 | 14 | from qcodes.utils import QCoDeSDeprecationWarning |
14 | 15 | from qcodes.validators import Strings, Validator |
15 | 16 |
|
|
18 | 19 | if TYPE_CHECKING: |
19 | 20 | from collections.abc import Callable |
20 | 21 |
|
21 | | - from qcodes.instrument import InstrumentBase |
| 22 | + from qcodes.instrument import Instrument |
22 | 23 |
|
23 | 24 |
|
24 | 25 | class ElapsedTimeParameter(Parameter): |
@@ -96,7 +97,9 @@ def t0(self) -> float: |
96 | 97 | return self._t0 |
97 | 98 |
|
98 | 99 |
|
99 | | -class InstrumentRefParameter(Parameter): |
| 100 | +class InstrumentRefParameter( |
| 101 | + Parameter[str, InstrumentTypeVar_co], Generic[InstrumentTypeVar_co] |
| 102 | +): |
100 | 103 | """ |
101 | 104 | An instrument reference parameter. |
102 | 105 |
|
@@ -134,12 +137,12 @@ def __init__( |
134 | 137 | self, |
135 | 138 | name: str, |
136 | 139 | *args: Any, |
137 | | - instrument: InstrumentBase | None = None, |
| 140 | + instrument: InstrumentTypeVar_co = None, |
138 | 141 | label: str | None = None, |
139 | 142 | unit: str | None = None, |
140 | 143 | get_cmd: str | Callable[..., Any] | Literal[False] | None = None, |
141 | 144 | set_cmd: str | Callable[..., Any] | Literal[False] | None = None, |
142 | | - initial_value: float | str | None = None, |
| 145 | + initial_value: str | None = None, |
143 | 146 | max_val_age: float | None = None, |
144 | 147 | vals: Validator[Any] | None = None, |
145 | 148 | docstring: str | None = None, |
@@ -229,16 +232,15 @@ def __init__( |
229 | 232 | **kwargs, |
230 | 233 | ) |
231 | 234 |
|
232 | | - # TODO(nulinspiratie) check class works now it's subclassed from Parameter |
233 | | - def get_instr(self) -> InstrumentBase: |
| 235 | + def get_instr(self) -> Instrument | None: |
234 | 236 | """ |
235 | 237 | Returns the instance of the instrument with the name equal to the |
236 | 238 | value of this parameter. |
237 | 239 | """ |
| 240 | + # lazy import to avoid circular import |
| 241 | + # since Instrument module depends on parameer module |
| 242 | + from qcodes.instrument import Instrument # noqa: PLC0415 |
| 243 | + |
238 | 244 | ref_instrument_name = self.get() |
239 | | - # note that _instrument refers to the instrument this parameter belongs |
240 | | - # to, while the ref_instrument_name is the instrument that is the value |
241 | | - # of this parameter. |
242 | | - if self._instrument is None: |
243 | | - raise RuntimeError("InstrumentRefParameter is not bound to an instrument.") |
244 | | - return self._instrument.find_instrument(ref_instrument_name) |
| 245 | + |
| 246 | + return Instrument.find_instrument(ref_instrument_name) |
0 commit comments