Skip to content

Commit 6cede55

Browse files
committed
Remove positional args on parameter classes
1 parent 3391be3 commit 6cede55

11 files changed

Lines changed: 228 additions & 1230 deletions

src/qcodes/parameters/array_parameter.py

Lines changed: 3 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import collections.abc
44
import os
5-
import warnings
6-
from typing import TYPE_CHECKING, Any, ClassVar
5+
from typing import TYPE_CHECKING, Any
76

87
import numpy as np
98

@@ -15,8 +14,6 @@
1514
has_loop = False
1615
from typing import Generic
1716

18-
from qcodes.utils import QCoDeSDeprecationWarning
19-
2017
from .parameter_base import InstrumentTypeVar_co, ParameterBase, ParameterDataTypeVar
2118
from .sequence_helpers import is_sequence_of
2219

@@ -43,9 +40,6 @@
4340
)
4441

4542

46-
_SHAPE_UNSET: Any = object()
47-
48-
4943
class ArrayParameter(
5044
ParameterBase[ParameterDataTypeVar, InstrumentTypeVar_co],
5145
Generic[ParameterDataTypeVar, InstrumentTypeVar_co],
@@ -135,27 +129,11 @@ class ArrayParameter(
135129
136130
"""
137131

138-
_DEPRECATED_POSITIONAL_ARGS: ClassVar[tuple[str, ...]] = (
139-
"shape",
140-
"instrument",
141-
"label",
142-
"unit",
143-
"setpoints",
144-
"setpoint_names",
145-
"setpoint_labels",
146-
"setpoint_units",
147-
"docstring",
148-
"snapshot_get",
149-
"snapshot_value",
150-
"snapshot_exclude",
151-
"metadata",
152-
)
153-
154132
def __init__(
155133
self,
156134
name: str,
157-
*args: Any,
158-
shape: Sequence[int] = _SHAPE_UNSET,
135+
*,
136+
shape: Sequence[int],
159137
# mypy seems to be confused here. The bound and default for InstrumentTypeVar_co
160138
# contains None but mypy will not allow it as a default as of v 1.19.0
161139
instrument: InstrumentTypeVar_co = None, # type: ignore[assignment]
@@ -172,87 +150,6 @@ def __init__(
172150
metadata: Mapping[Any, Any] | None = None,
173151
**kwargs: Any,
174152
) -> None:
175-
if args:
176-
# TODO: After QCoDeS 0.57 remove the args argument and delete this code block.
177-
positional_names = __class__._DEPRECATED_POSITIONAL_ARGS
178-
if len(args) > len(positional_names):
179-
raise TypeError(
180-
f"{type(self).__name__}.__init__() takes at most "
181-
f"{len(positional_names) + 2} positional arguments "
182-
f"({len(args) + 2} given)"
183-
)
184-
185-
_defaults: dict[str, Any] = {
186-
"shape": _SHAPE_UNSET,
187-
"instrument": None,
188-
"label": None,
189-
"unit": None,
190-
"setpoints": None,
191-
"setpoint_names": None,
192-
"setpoint_labels": None,
193-
"setpoint_units": None,
194-
"docstring": None,
195-
"snapshot_get": True,
196-
"snapshot_value": False,
197-
"snapshot_exclude": False,
198-
"metadata": None,
199-
}
200-
201-
_kwarg_vals: dict[str, Any] = {
202-
"shape": shape,
203-
"instrument": instrument,
204-
"label": label,
205-
"unit": unit,
206-
"setpoints": setpoints,
207-
"setpoint_names": setpoint_names,
208-
"setpoint_labels": setpoint_labels,
209-
"setpoint_units": setpoint_units,
210-
"docstring": docstring,
211-
"snapshot_get": snapshot_get,
212-
"snapshot_value": snapshot_value,
213-
"snapshot_exclude": snapshot_exclude,
214-
"metadata": metadata,
215-
}
216-
217-
for i in range(len(args)):
218-
arg_name = positional_names[i]
219-
if _kwarg_vals[arg_name] is not _defaults[arg_name]:
220-
raise TypeError(
221-
f"{type(self).__name__}.__init__() got multiple "
222-
f"values for argument '{arg_name}'"
223-
)
224-
225-
positional_arg_names = positional_names[: len(args)]
226-
names_str = ", ".join(f"'{n}'" for n in positional_arg_names)
227-
warnings.warn(
228-
f"Passing {names_str} as positional argument(s) to "
229-
f"{type(self).__name__} is deprecated. "
230-
f"Please pass them as keyword arguments.",
231-
QCoDeSDeprecationWarning,
232-
stacklevel=2,
233-
)
234-
235-
_pos = dict(zip(positional_names, args))
236-
shape = _pos.get("shape", shape)
237-
instrument = _pos.get("instrument", instrument)
238-
label = _pos.get("label", label)
239-
unit = _pos.get("unit", unit)
240-
setpoints = _pos.get("setpoints", setpoints)
241-
setpoint_names = _pos.get("setpoint_names", setpoint_names)
242-
setpoint_labels = _pos.get("setpoint_labels", setpoint_labels)
243-
setpoint_units = _pos.get("setpoint_units", setpoint_units)
244-
docstring = _pos.get("docstring", docstring)
245-
snapshot_get = _pos.get("snapshot_get", snapshot_get)
246-
snapshot_value = _pos.get("snapshot_value", snapshot_value)
247-
snapshot_exclude = _pos.get("snapshot_exclude", snapshot_exclude)
248-
metadata = _pos.get("metadata", metadata)
249-
250-
if shape is _SHAPE_UNSET:
251-
raise TypeError(
252-
f"{type(self).__name__}.__init__() missing required "
253-
f"keyword argument: 'shape'"
254-
)
255-
256153
super().__init__(
257154
name,
258155
instrument=instrument,

src/qcodes/parameters/delegate_parameter.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
from __future__ import annotations
22

3-
import warnings
43
from typing import TYPE_CHECKING, Any, Generic
54

65
from typing_extensions import TypeVar
76

8-
from qcodes.utils import QCoDeSDeprecationWarning
9-
107
from .parameter import Parameter
118
from .parameter_base import InstrumentTypeVar_co, ParameterDataTypeVar
129

@@ -179,19 +176,8 @@ def __init__(
179176
self,
180177
name: str,
181178
source: Parameter | None,
182-
*args: Any,
183179
**kwargs: Any,
184180
):
185-
if args:
186-
# TODO: After QCoDeS 0.57 remove the args argument
187-
# and delete this code block.
188-
warnings.warn(
189-
"Passing extra positional arguments to "
190-
f"{type(self).__name__} is deprecated. "
191-
"Please pass them as keyword arguments.",
192-
QCoDeSDeprecationWarning,
193-
stacklevel=2,
194-
)
195181
if "bind_to_instrument" not in kwargs.keys():
196182
kwargs["bind_to_instrument"] = False
197183

@@ -213,7 +199,7 @@ def __init__(
213199

214200
initial_cache_value = kwargs.pop("initial_cache_value", None)
215201
self.source = source
216-
super().__init__(name, *args, **kwargs)
202+
super().__init__(name, **kwargs)
217203
self.label = kwargs.get("label", None)
218204
self.unit = kwargs.get("unit", None)
219205

src/qcodes/parameters/group_parameter.py

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66

77
from __future__ import annotations
88

9-
import warnings
109
from collections import OrderedDict
11-
from typing import TYPE_CHECKING, Any, ClassVar
12-
13-
from qcodes.utils import QCoDeSDeprecationWarning
10+
from typing import TYPE_CHECKING, Any
1411

1512
from .parameter import Parameter
1613

@@ -51,61 +48,14 @@ class GroupParameter(Parameter):
5148
5249
"""
5350

54-
_DEPRECATED_POSITIONAL_ARGS: ClassVar[tuple[str, ...]] = (
55-
"instrument",
56-
"initial_value",
57-
)
58-
5951
def __init__(
6052
self,
6153
name: str,
62-
*args: Any,
54+
*,
6355
instrument: InstrumentBase | None = None,
6456
initial_value: float | str | None = None,
6557
**kwargs: Any,
6658
) -> None:
67-
if args:
68-
# TODO: After QCoDeS 0.57 remove the args argument and delete this code block.
69-
positional_names = __class__._DEPRECATED_POSITIONAL_ARGS
70-
if len(args) > len(positional_names):
71-
raise TypeError(
72-
f"{type(self).__name__}.__init__() takes at most "
73-
f"{len(positional_names) + 2} positional arguments "
74-
f"({len(args) + 2} given)"
75-
)
76-
77-
_defaults: dict[str, Any] = {
78-
"instrument": None,
79-
"initial_value": None,
80-
}
81-
82-
_kwarg_vals: dict[str, Any] = {
83-
"instrument": instrument,
84-
"initial_value": initial_value,
85-
}
86-
87-
for i in range(len(args)):
88-
arg_name = positional_names[i]
89-
if _kwarg_vals[arg_name] is not _defaults[arg_name]:
90-
raise TypeError(
91-
f"{type(self).__name__}.__init__() got multiple "
92-
f"values for argument '{arg_name}'"
93-
)
94-
95-
positional_arg_names = positional_names[: len(args)]
96-
names_str = ", ".join(f"'{n}'" for n in positional_arg_names)
97-
warnings.warn(
98-
f"Passing {names_str} as positional argument(s) to "
99-
f"{type(self).__name__} is deprecated. "
100-
f"Please pass them as keyword arguments.",
101-
QCoDeSDeprecationWarning,
102-
stacklevel=2,
103-
)
104-
105-
_pos = dict(zip(positional_names, args))
106-
instrument = _pos.get("instrument", instrument)
107-
initial_value = _pos.get("initial_value", initial_value)
108-
10959
if "set_cmd" in kwargs or "get_cmd" in kwargs:
11060
raise ValueError(
11161
"A GroupParameter does not use 'set_cmd' or 'get_cmd' kwarg"

src/qcodes/parameters/grouped_parameter.py

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
from __future__ import annotations
22

33
import logging
4-
import warnings
54
from collections import OrderedDict, namedtuple
6-
from typing import TYPE_CHECKING, Any, ClassVar
7-
8-
from qcodes.utils import QCoDeSDeprecationWarning
5+
from typing import TYPE_CHECKING, Any
96

107
from .delegate_parameter import DelegateParameter
118
from .group_parameter import Group, GroupParameter
@@ -168,74 +165,15 @@ class GroupedParameter(ParameterBase):
168165
169166
"""
170167

171-
_DEPRECATED_POSITIONAL_ARGS: ClassVar[tuple[str, ...]] = (
172-
"group",
173-
"unit",
174-
"label",
175-
)
176-
177-
_GROUP_UNSET: Any = object()
178-
179168
def __init__(
180169
self,
181170
name: str,
182-
*args: Any,
183-
group: DelegateGroup = _GROUP_UNSET,
171+
*,
172+
group: DelegateGroup,
184173
unit: str | None = None,
185174
label: str | None = None,
186175
**kwargs: Any,
187176
):
188-
if args:
189-
# TODO: After QCoDeS 0.57 remove the args argument and delete this code block.
190-
positional_names = __class__._DEPRECATED_POSITIONAL_ARGS
191-
if len(args) > len(positional_names):
192-
raise TypeError(
193-
f"{type(self).__name__}.__init__() takes at most "
194-
f"{len(positional_names) + 2} positional arguments "
195-
f"({len(args) + 2} given)"
196-
)
197-
198-
_defaults: dict[str, Any] = {
199-
"group": self._GROUP_UNSET,
200-
"unit": None,
201-
"label": None,
202-
}
203-
204-
_kwarg_vals: dict[str, Any] = {
205-
"group": group,
206-
"unit": unit,
207-
"label": label,
208-
}
209-
210-
for i in range(len(args)):
211-
arg_name = positional_names[i]
212-
if _kwarg_vals[arg_name] is not _defaults[arg_name]:
213-
raise TypeError(
214-
f"{type(self).__name__}.__init__() got multiple "
215-
f"values for argument '{arg_name}'"
216-
)
217-
218-
positional_arg_names = positional_names[: len(args)]
219-
names_str = ", ".join(f"'{n}'" for n in positional_arg_names)
220-
warnings.warn(
221-
f"Passing {names_str} as positional argument(s) to "
222-
f"{type(self).__name__} is deprecated. "
223-
f"Please pass them as keyword arguments.",
224-
QCoDeSDeprecationWarning,
225-
stacklevel=2,
226-
)
227-
228-
_pos = dict(zip(positional_names, args))
229-
group = _pos.get("group", group)
230-
unit = _pos.get("unit", unit)
231-
label = _pos.get("label", label)
232-
233-
if group is self._GROUP_UNSET:
234-
raise TypeError(
235-
f"{type(self).__name__}.__init__() missing required "
236-
f"keyword argument: 'group'"
237-
)
238-
239177
super().__init__(name, **kwargs)
240178
self.label = name if label is None else label
241179
self.unit = unit if unit is not None else ""

0 commit comments

Comments
 (0)