Skip to content

Commit

Permalink
Fix type checking with mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshnielsen committed Feb 7, 2025
1 parent e5abfdd commit 71ad4bd
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/qcodes/instrument/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ def __init__(
self._parent = parent
self._name = name
if not isinstance(chan_type, type) or not issubclass(
chan_type, InstrumentChannel
chan_type, InstrumentModule
):
raise ValueError(
"ChannelTuple can only hold instances of type InstrumentChannel"
"ChannelTuple can only hold instances of type InstrumentModule"
)
if not isinstance(multichan_paramclass, type) or not issubclass(
multichan_paramclass, MultiChannelInstrumentParameter
Expand All @@ -166,7 +166,7 @@ def __init__(
"MultiChannelInstrumentParameter"
)

self._chan_type = chan_type
self._chan_type: type[InstrumentModuleType] = chan_type
self._snapshotable = snapshotable
self._paramclass = multichan_paramclass

Expand Down Expand Up @@ -270,7 +270,9 @@ def __add__(self: Self, other: ChannelTuple) -> Self:
if self._parent != other._parent:
raise ValueError("Can only add channels from the same parent together.")

return type(self)(
# mypy does not understand that type[self] is type[self]
# it infers that type(self) == ChannelTuple[Any] e.g. not generic
return type(self)( # type: ignore[return-value]
self._parent,
self._name,
self._chan_type,
Expand Down Expand Up @@ -1066,7 +1068,7 @@ def exists_on_instrument(self) -> bool:
return self._exists_on_instrument


class AutoLoadableChannelList(ChannelList):
class AutoLoadableChannelList(ChannelList[AutoLoadableInstrumentChannel]):
"""
Extends the QCoDeS :class:`ChannelList` class to add the following features:
- Automatically create channel objects on initialization
Expand Down Expand Up @@ -1112,7 +1114,7 @@ def __init__(
self,
parent: Instrument,
name: str,
chan_type: type,
chan_type: type[AutoLoadableInstrumentChannel],
chan_list: Sequence[AutoLoadableInstrumentChannel] | None = None,
snapshotable: bool = True,
multichan_paramclass: type = MultiChannelInstrumentParameter,
Expand All @@ -1121,7 +1123,7 @@ def __init__(
super().__init__(
parent, name, chan_type, chan_list, snapshotable, multichan_paramclass
)
new_channels = self._chan_type.load_from_instrument( # type: ignore[attr-defined]
new_channels = self._chan_type.load_from_instrument(
self._parent, channel_list=self, **kwargs
)

Expand All @@ -1139,7 +1141,7 @@ def add(self, **kwargs: Any) -> AutoLoadableInstrumentChannel:
Newly created instance of the channel class
"""
new_channel = self._chan_type.new_instance( # type: ignore[attr-defined]
new_channel = self._chan_type.new_instance(
self._parent, create_on_instrument=True, channel_list=self, **kwargs
)

Expand Down

0 comments on commit 71ad4bd

Please sign in to comment.