Skip to content

Commit 7025c17

Browse files
committed
Rename typevar as suggested in review
1 parent 70fe7b6 commit 7025c17

File tree

6 files changed

+34
-32
lines changed

6 files changed

+34
-32
lines changed

src/qcodes/parameters/array_parameter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
has_loop = False
1515
from typing import Generic
1616

17-
from .parameter_base import InstrumentType_co, ParameterBase, ParameterDataTypeVar
17+
from .parameter_base import InstrumentTypeVar_co, ParameterBase, ParameterDataTypeVar
1818
from .sequence_helpers import is_sequence_of
1919

2020
if TYPE_CHECKING:
@@ -41,8 +41,8 @@
4141

4242

4343
class ArrayParameter(
44-
ParameterBase[ParameterDataTypeVar, InstrumentType_co],
45-
Generic[ParameterDataTypeVar, InstrumentType_co],
44+
ParameterBase[ParameterDataTypeVar, InstrumentTypeVar_co],
45+
Generic[ParameterDataTypeVar, InstrumentTypeVar_co],
4646
):
4747
"""
4848
A gettable parameter that returns an array of values.
@@ -133,9 +133,9 @@ def __init__(
133133
self,
134134
name: str,
135135
shape: Sequence[int],
136-
# mypy seems to be confused here. The bound and default for InstrumentType_co
136+
# mypy seems to be confused here. The bound and default for InstrumentTypeVar_co
137137
# contains None but mypy will not allow it as a default as of v 1.19.0
138-
instrument: InstrumentType_co = None, # type: ignore[assignment]
138+
instrument: InstrumentTypeVar_co = None, # type: ignore[assignment]
139139
label: str | None = None,
140140
unit: str | None = None,
141141
setpoints: Sequence[Any] | None = None,

src/qcodes/parameters/delegate_parameter.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing_extensions import TypeVar
66

77
from .parameter import Parameter
8-
from .parameter_base import InstrumentType_co, ParameterDataTypeVar
8+
from .parameter_base import InstrumentTypeVar_co, ParameterDataTypeVar
99

1010
if TYPE_CHECKING:
1111
from collections.abc import Sequence
@@ -22,17 +22,17 @@
2222
# Generic type variables for inner cache class
2323
# these need to be different variables such that both classes can be generic
2424
_local_ParameterDataTypeVar = TypeVar("_local_ParameterDataTypeVar", default=Any)
25-
_local_InstrumentType_co = TypeVar(
26-
"_local_InstrumentType_co",
25+
_local_InstrumentTypeVar_co = TypeVar(
26+
"_local_InstrumentTypeVar_co",
2727
bound="InstrumentBase | None",
2828
default="InstrumentBase | None",
2929
covariant=True,
3030
)
3131

3232

3333
class DelegateParameter(
34-
Parameter[ParameterDataTypeVar, InstrumentType_co],
35-
Generic[ParameterDataTypeVar, InstrumentType_co],
34+
Parameter[ParameterDataTypeVar, InstrumentTypeVar_co],
35+
Generic[ParameterDataTypeVar, InstrumentTypeVar_co],
3636
):
3737
"""
3838
The :class:`.DelegateParameter` wraps a given `source` :class:`Parameter`.
@@ -72,12 +72,12 @@ class DelegateParameter(
7272
"""
7373

7474
class _DelegateCache(
75-
Generic[_local_ParameterDataTypeVar, _local_InstrumentType_co]
75+
Generic[_local_ParameterDataTypeVar, _local_InstrumentTypeVar_co]
7676
):
7777
def __init__(
7878
self,
7979
parameter: DelegateParameter[
80-
_local_ParameterDataTypeVar, _local_InstrumentType_co
80+
_local_ParameterDataTypeVar, _local_InstrumentTypeVar_co
8181
],
8282
):
8383
self._parameter = parameter
@@ -210,7 +210,9 @@ def __init__(
210210
# i.e. _SetParamContext overrides it
211211
self._settable = True
212212

213-
self.cache = self._DelegateCache[ParameterDataTypeVar, InstrumentType_co](self)
213+
self.cache = self._DelegateCache[ParameterDataTypeVar, InstrumentTypeVar_co](
214+
self
215+
)
214216
if initial_cache_value is not None:
215217
self.cache.set(initial_cache_value)
216218

src/qcodes/parameters/multi_parameter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import numpy as np
88

9-
from .parameter_base import InstrumentType_co, ParameterBase, ParameterDataTypeVar
9+
from .parameter_base import InstrumentTypeVar_co, ParameterBase, ParameterDataTypeVar
1010
from .sequence_helpers import is_sequence_of
1111

1212
try:
@@ -48,8 +48,8 @@ def _is_nested_sequence_or_none(
4848

4949

5050
class MultiParameter(
51-
ParameterBase[ParameterDataTypeVar, InstrumentType_co],
52-
Generic[ParameterDataTypeVar, InstrumentType_co],
51+
ParameterBase[ParameterDataTypeVar, InstrumentTypeVar_co],
52+
Generic[ParameterDataTypeVar, InstrumentTypeVar_co],
5353
):
5454
"""
5555
A gettable parameter that returns multiple values with separate names,
@@ -141,9 +141,9 @@ def __init__(
141141
name: str,
142142
names: Sequence[str],
143143
shapes: Sequence[Sequence[int]],
144-
# mypy seems to be confused here. The bound and default for InstrumentType_co
144+
# mypy seems to be confused here. The bound and default for InstrumentTypeVar_co
145145
# contains None but mypy will not allow it as a default as of v 1.19.0
146-
instrument: InstrumentType_co = None, # type: ignore[assignment]
146+
instrument: InstrumentTypeVar_co = None, # type: ignore[assignment]
147147
labels: Sequence[str] | None = None,
148148
units: Sequence[str] | None = None,
149149
setpoints: Sequence[Sequence[Any]] | None = None,

src/qcodes/parameters/parameter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from .command import Command
1212
from .parameter_base import (
13-
InstrumentType_co,
13+
InstrumentTypeVar_co,
1414
ParameterBase,
1515
ParameterDataTypeVar,
1616
ParamRawDataType,
@@ -30,8 +30,8 @@
3030

3131

3232
class Parameter(
33-
ParameterBase[ParameterDataTypeVar, InstrumentType_co],
34-
Generic[ParameterDataTypeVar, InstrumentType_co],
33+
ParameterBase[ParameterDataTypeVar, InstrumentTypeVar_co],
34+
Generic[ParameterDataTypeVar, InstrumentTypeVar_co],
3535
):
3636
"""
3737
A parameter represents a single degree of freedom. Most often,
@@ -180,9 +180,9 @@ class Parameter(
180180
def __init__(
181181
self,
182182
name: str,
183-
# mypy seems to be confused here. The bound and default for InstrumentType_co
183+
# mypy seems to be confused here. The bound and default for InstrumentTypeVar_co
184184
# contains None but mypy will not allow None as a default as of v 1.19.0
185-
instrument: InstrumentType_co = None, # type: ignore[assignment]
185+
instrument: InstrumentTypeVar_co = None, # type: ignore[assignment]
186186
label: str | None = None,
187187
unit: str | None = None,
188188
get_cmd: str | Callable[..., Any] | Literal[False] | None = None,

src/qcodes/parameters/parameter_base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545
from qcodes.instrument import InstrumentBase
4646
from qcodes.logger.instrument_logger import InstrumentLoggerAdapter
4747
ParameterDataTypeVar = TypeVar("ParameterDataTypeVar", default=Any)
48-
# InstrumentType_co is a covariant type variable representing the instrument
48+
# InstrumentTypeVar_co is a covariant type variable representing the instrument
4949
# type associated with the parameter. It needs to be covariant to allow passing
5050
# a Parameter bound to None or a specific instrument where the default is used in the type hint.
5151
# Otherwise we see errors such as
5252
# Type parameter "InstrumentType@ParameterBase" is invariant, but "None" is not the same as "InstrumentBase | None"
53-
InstrumentType_co = TypeVar(
54-
"InstrumentType_co",
53+
InstrumentTypeVar_co = TypeVar(
54+
"InstrumentTypeVar_co",
5555
bound="InstrumentBase | None",
5656
default="InstrumentBase | None",
5757
covariant=True,
@@ -125,7 +125,7 @@ def invert_val_mapping(val_mapping: Mapping[Any, Any]) -> dict[Any, Any]:
125125

126126

127127
class ParameterBase(
128-
MetadatableWithName, Generic[ParameterDataTypeVar, InstrumentType_co]
128+
MetadatableWithName, Generic[ParameterDataTypeVar, InstrumentTypeVar_co]
129129
):
130130
"""
131131
Shared behavior for all parameters. Not intended to be used
@@ -229,7 +229,7 @@ class ParameterBase(
229229
def __init__(
230230
self,
231231
name: str,
232-
instrument: InstrumentType_co,
232+
instrument: InstrumentTypeVar_co,
233233
snapshot_get: bool = True,
234234
metadata: Mapping[Any, Any] | None = None,
235235
step: float | None = None,
@@ -1063,7 +1063,7 @@ def register_name(self) -> str:
10631063
return self._register_name or self.full_name
10641064

10651065
@property
1066-
def instrument(self) -> InstrumentType_co:
1066+
def instrument(self) -> InstrumentTypeVar_co:
10671067
"""
10681068
Return the first instrument that this parameter is bound to.
10691069
E.g if this is bound to a channel it will return the channel

src/qcodes/parameters/parameter_with_setpoints.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Parameter,
1010
)
1111
from qcodes.parameters.parameter_base import (
12-
InstrumentType_co,
12+
InstrumentTypeVar_co,
1313
ParameterBase,
1414
ParameterDataTypeVar,
1515
ParameterSet,
@@ -26,8 +26,8 @@
2626

2727

2828
class ParameterWithSetpoints(
29-
Parameter[ParameterDataTypeVar, InstrumentType_co],
30-
Generic[ParameterDataTypeVar, InstrumentType_co],
29+
Parameter[ParameterDataTypeVar, InstrumentTypeVar_co],
30+
Generic[ParameterDataTypeVar, InstrumentTypeVar_co],
3131
):
3232
"""
3333
A parameter that has associated setpoints. The setpoints is nothing

0 commit comments

Comments
 (0)