|
5 | 5 | import logging |
6 | 6 | import warnings |
7 | 7 | from collections.abc import Callable, Mapping, Sequence |
8 | | -from typing import TYPE_CHECKING, Any |
| 8 | +from typing import TYPE_CHECKING, Any, Type, TypeVar, cast |
9 | 9 |
|
10 | 10 | import numpy as np |
11 | 11 |
|
|
22 | 22 |
|
23 | 23 | log = logging.getLogger(__name__) |
24 | 24 |
|
| 25 | +TParameter = TypeVar("TParameter", bound=ParameterBase) |
| 26 | + |
25 | 27 |
|
26 | 28 | class InstrumentBase(Metadatable, DelegateAttributes): |
27 | 29 | """ |
@@ -99,9 +101,9 @@ def label(self, label: str) -> None: |
99 | 101 | def add_parameter( |
100 | 102 | self, |
101 | 103 | name: str, |
102 | | - parameter_class: type[ParameterBase] | None = None, |
| 104 | + parameter_class: type[TParameter] | None = None, |
103 | 105 | **kwargs: Any, |
104 | | - ) -> None: |
| 106 | + ) -> TParameter: |
105 | 107 | """ |
106 | 108 | Bind one Parameter to this instrument. |
107 | 109 |
|
@@ -131,7 +133,7 @@ def add_parameter( |
131 | 133 | one. |
132 | 134 | """ |
133 | 135 | if parameter_class is None: |
134 | | - parameter_class = Parameter |
| 136 | + parameter_class = cast(Type[TParameter], Parameter) |
135 | 137 |
|
136 | 138 | if "bind_to_instrument" not in kwargs.keys(): |
137 | 139 | kwargs["bind_to_instrument"] = True |
@@ -159,6 +161,7 @@ def add_parameter( |
159 | 161 | QCoDeSDeprecationWarning, |
160 | 162 | ) |
161 | 163 | self.parameters[name] = param |
| 164 | + return param |
162 | 165 |
|
163 | 166 | def add_function(self, name: str, **kwargs: Any) -> None: |
164 | 167 | """ |
|
0 commit comments