Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typechecking with newest qcodes and Numpy #116

Merged
merged 6 commits into from Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pytest.yaml
Expand Up @@ -68,6 +68,7 @@ jobs:
pip install .
- name: Run Mypy
run: mypy qcodes_contrib_drivers
if: matrix.python-version != '3.7'
- name: Run tests
run: |
pytest --cov=qcodes_contrib_drivers --cov-report xml --cov-config=setup.cfg qcodes_contrib_drivers
Expand Down
9 changes: 4 additions & 5 deletions qcodes_contrib_drivers/drivers/NationalInstruments/Switch.py
@@ -1,9 +1,8 @@
import logging
from typing import Optional, Dict, List, cast
from typing import Dict, List, Optional, cast

from qcodes import Instrument, InstrumentChannel, ChannelList

from niswitch import Session, PathCapability
from niswitch import PathCapability, Session
from qcodes import ChannelList, Instrument, InstrumentChannel

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -159,5 +158,5 @@ def disconnect_from_all(self) -> None:
Disconnect this channel from all channels it is connected to.
"""
while len(self.connection_list) > 0:
ch = cast(InstrumentChannel, self.connection_list[0])
ch = self.connection_list[0]
self.disconnect_from(ch)
4 changes: 2 additions & 2 deletions qcodes_contrib_drivers/drivers/QDevil/QDAC2.py
Expand Up @@ -1554,14 +1554,14 @@ def __exit__(self, exc_type, exc_val, exc_tb):
# Let Arrangement take care of freeing triggers
return False

def actual_values_V(self, gate: str) -> Sequence[float]:
def actual_values_V(self, gate: str) -> np.ndarray:
"""The corrected values that would actually be sent to the gate

Args:
gate (str): Name of gate

Returns:
Sequence[float]: Corrected voltages
np.ndarray: Corrected voltages
"""
index = self._arrangement._gate_index(gate)
return self._sweep[:, index]
Expand Down
4 changes: 3 additions & 1 deletion qcodes_contrib_drivers/drivers/Spectrum/M4i.py
Expand Up @@ -988,7 +988,9 @@ def _transfer_buffer_numpy(self, memsize: int, numch: int, bytes_per_sample=2) -
raise Exception(f'Error transferring data: {_errormsg_dict[res]} (0x{res:04x})')

# convert buffer to numpy array
output = np.frombuffer(data_buffer, dtype=sample_ctype)
# this does not typecheck with numpy 1.22 should be updated
# by someone with access to test on the real data.
output = np.frombuffer(data_buffer, dtype=sample_ctype) # type: ignore[call-overload]

return output

Expand Down
13 changes: 10 additions & 3 deletions qcodes_contrib_drivers/tests/QDevil/test_sim_qdac2_init.py
Expand Up @@ -13,8 +13,11 @@ def test_refuse_wrong_model():
# -----------------------------------------------------------------------
assert 'Unknown model' in repr(error)
# Circumvent Instrument not handling exceptions in constructor.
Instrument._all_instruments.pop(wrong_instrument)

# In qcodes < 0.32
try:
Instrument._all_instruments.pop(wrong_instrument)
except KeyError:
pass

def test_refuse_incompatible_firmware():
# -----------------------------------------------------------------------
Expand All @@ -23,4 +26,8 @@ def test_refuse_incompatible_firmware():
# -----------------------------------------------------------------------
assert 'Incompatible firmware' in repr(error)
# Circumvent Instrument not handling exceptions in constructor.
Instrument._all_instruments.pop('qdac')
# In qcodes < 0.32
try:
Instrument._all_instruments.pop('qdac')
except KeyError:
pass
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -46,6 +46,7 @@ show_column_numbers = True
warn_unused_ignores = True
warn_unused_configs = True
warn_redundant_casts = True
show_error_codes = True

[mypy-qcodes_contrib_drivers._version]
ignore_errors = True
Expand Down