From 5d2f3702637b4a1f2982b14c78c9b6b5db3c8bbc Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Tue, 2 Jan 2024 15:45:36 +0100 Subject: [PATCH 1/6] fix unbound pyright error --- src/qcodes/parameters/array_parameter.py | 36 +++++++++++--------- src/qcodes/parameters/multi_parameter.py | 43 +++++++++++------------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/qcodes/parameters/array_parameter.py b/src/qcodes/parameters/array_parameter.py index f9ae58f0881..6fc7b2196f4 100644 --- a/src/qcodes/parameters/array_parameter.py +++ b/src/qcodes/parameters/array_parameter.py @@ -21,6 +21,25 @@ from qcodes.instrument import InstrumentBase +try: + from qcodes_loop.data.data_array import DataArray + + _SP_TYPES: tuple[type, ...] = ( + type(None), + DataArray, + collections.abc.Sequence, + collections.abc.Iterator, + np.ndarray, + ) +except ImportError: + _SP_TYPES: tuple[type, ...] = ( + type(None), + collections.abc.Sequence, + collections.abc.Iterator, + np.ndarray, + ) + + class ArrayParameter(ParameterBase): """ A gettable parameter that returns an array of values. @@ -154,23 +173,8 @@ def __init__( # require one setpoint per dimension of shape sp_shape = (len(shape),) - if has_loop: - sp_types: tuple[type, ...] = ( - nt, - DataArray, - collections.abc.Sequence, - collections.abc.Iterator, - np.ndarray, - ) - else: - sp_types = ( - nt, - collections.abc.Sequence, - collections.abc.Iterator, - np.ndarray, - ) if setpoints is not None and not is_sequence_of( - setpoints, sp_types, shape=sp_shape + setpoints, _SP_TYPES, shape=sp_shape ): raise ValueError("setpoints must be a tuple of arrays") if setpoint_names is not None and not is_sequence_of( diff --git a/src/qcodes/parameters/multi_parameter.py b/src/qcodes/parameters/multi_parameter.py index 232108f3f39..cc9153bb2ca 100644 --- a/src/qcodes/parameters/multi_parameter.py +++ b/src/qcodes/parameters/multi_parameter.py @@ -6,20 +6,30 @@ import numpy as np -try: - from qcodes_loop.data.data_array import DataArray - - has_loop = True -except ImportError: - has_loop = False - - from .parameter_base import ParameterBase from .sequence_helpers import is_sequence_of if TYPE_CHECKING: from qcodes.instrument import InstrumentBase +try: + from qcodes_loop.data.data_array import DataArray + + _SP_TYPES: tuple[type, ...] = ( + type(None), + DataArray, + Sequence, + Iterator, + np.ndarray, + ) +except ImportError: + _SP_TYPES: tuple[type, ...] = ( + type(None), + Sequence, + Iterator, + np.ndarray, + ) + def _is_nested_sequence_or_none( obj: Any, @@ -180,22 +190,7 @@ def __init__( ) self.shapes = shapes - if has_loop: - sp_types: tuple[type, ...] = ( - nt, - DataArray, - Sequence, - Iterator, - np.ndarray, - ) - else: - sp_types = ( - nt, - Sequence, - Iterator, - np.ndarray, - ) - if not _is_nested_sequence_or_none(setpoints, sp_types, shapes): + if not _is_nested_sequence_or_none(setpoints, _SP_TYPES, shapes): raise ValueError("setpoints must be a tuple of tuples of arrays") if not _is_nested_sequence_or_none(setpoint_names, (nt, str), shapes): From c431b0aa1b2118411eb05e56787526afaa2e5f2e Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Thu, 18 Jan 2024 11:38:07 +0100 Subject: [PATCH 2/6] typecheck with pyright 1.1.347 --- .github/workflows/pytest.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index cb567f4b604..b2fbaa229da 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -87,7 +87,7 @@ jobs: if: ${{ !matrix.min-version }} - uses: jakebailey/pyright-action@03ab3c98073356eb56161009632b39fc2666321b # v2.0.1 with: - version: 1.1.339 + version: 1.1.347 if: ${{ !matrix.min-version }} - name: Run Mypy run: mypy -p qcodes From 06cc75335060b496d7d7bdd24e95bd825a5d875c Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Fri, 2 Feb 2024 15:45:06 +0100 Subject: [PATCH 3/6] upgrade to pyright 1.1.349 --- .github/workflows/pytest.yaml | 2 +- src/qcodes/instrument_drivers/Keithley/_Keithley_2600.py | 2 +- src/qcodes/sphinx_extensions/parse_parameter_attr.py | 2 +- src/qcodes/utils/deprecate.py | 6 ++---- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index b2fbaa229da..3a3a17b5a03 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -87,7 +87,7 @@ jobs: if: ${{ !matrix.min-version }} - uses: jakebailey/pyright-action@03ab3c98073356eb56161009632b39fc2666321b # v2.0.1 with: - version: 1.1.347 + version: 1.1.349 if: ${{ !matrix.min-version }} - name: Run Mypy run: mypy -p qcodes diff --git a/src/qcodes/instrument_drivers/Keithley/_Keithley_2600.py b/src/qcodes/instrument_drivers/Keithley/_Keithley_2600.py index 809131a5a1f..af65f4ecf74 100644 --- a/src/qcodes/instrument_drivers/Keithley/_Keithley_2600.py +++ b/src/qcodes/instrument_drivers/Keithley/_Keithley_2600.py @@ -259,7 +259,7 @@ def _parse_response(data: str) -> tuple[float, Keithley2600MeasurementStatus]: status = _from_bits_tuple_to_status[ (status_bits[0], status_bits[1]) - ] # pyright: ignore[reportGeneralTypeIssues] + ] # pyright: ignore[reportArgumentType] return float(value), status diff --git a/src/qcodes/sphinx_extensions/parse_parameter_attr.py b/src/qcodes/sphinx_extensions/parse_parameter_attr.py index 4ac6f61069a..4e118a5d680 100644 --- a/src/qcodes/sphinx_extensions/parse_parameter_attr.py +++ b/src/qcodes/sphinx_extensions/parse_parameter_attr.py @@ -63,7 +63,7 @@ def find_init_func( for child in node.children: if ( isinstance(child, parso.python.tree.Function) - and child.name.value # pyright: ignore[reportGeneralTypeIssues] + and child.name.value # pyright: ignore[reportAttributeAccessIssue] == "__init__" ): nodes.append(child) diff --git a/src/qcodes/utils/deprecate.py b/src/qcodes/utils/deprecate.py index 6c50ce262bc..3b8d23651e5 100644 --- a/src/qcodes/utils/deprecate.py +++ b/src/qcodes/utils/deprecate.py @@ -77,7 +77,7 @@ def actual_decorator(obj: Any) -> Any: if isinstance(obj, (types.FunctionType, types.MethodType)): func = cast(Callable[..., Any], obj) # pylint: disable=no-value-for-parameter - return decorate_callable(func) # pyright: ignore[reportGeneralTypeIssues] + return decorate_callable(func) # pyright: ignore[reportCallIssue] # pylint: enable=no-value-for-parameter else: # this would need to be recursive @@ -98,9 +98,7 @@ def actual_decorator(obj: Any) -> Any: setattr( obj, m_name, - decorate_callable( - m - ), # pyright: ignore[reportGeneralTypeIssues] + decorate_callable(m), # pyright: ignore[reportCallIssue] ) # pylint: enable=no-value-for-parameter return obj From 32bf66c75601ecd6e667e52cc1ae7dccff2849df Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Fri, 2 Feb 2024 16:00:45 +0100 Subject: [PATCH 4/6] remove uncorrect type hints --- src/qcodes/dataset/sqlite/queries.py | 4 +--- src/qcodes/parameters/array_parameter.py | 2 +- src/qcodes/parameters/multi_parameter.py | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/qcodes/dataset/sqlite/queries.py b/src/qcodes/dataset/sqlite/queries.py index 15a4b4322db..cca73b63df2 100644 --- a/src/qcodes/dataset/sqlite/queries.py +++ b/src/qcodes/dataset/sqlite/queries.py @@ -242,9 +242,7 @@ def get_parameter_data_for_one_paramtree( # faster than transposing the data using np.array.transpose res_t = map(list, zip(*data)) - specs_and_data: zip_longest[ - tuple[ParamSpecBase | Sequence[Any], Sequence[Any]] - ] = zip_longest(paramspecs, res_t, fillvalue=()) + specs_and_data = zip_longest(paramspecs, res_t, fillvalue=()) for paramspec, column_data in specs_and_data: assert isinstance(paramspec, ParamSpecBase) diff --git a/src/qcodes/parameters/array_parameter.py b/src/qcodes/parameters/array_parameter.py index 6fc7b2196f4..013cc66d026 100644 --- a/src/qcodes/parameters/array_parameter.py +++ b/src/qcodes/parameters/array_parameter.py @@ -32,7 +32,7 @@ np.ndarray, ) except ImportError: - _SP_TYPES: tuple[type, ...] = ( + _SP_TYPES = ( type(None), collections.abc.Sequence, collections.abc.Iterator, diff --git a/src/qcodes/parameters/multi_parameter.py b/src/qcodes/parameters/multi_parameter.py index cc9153bb2ca..960db6fb3ca 100644 --- a/src/qcodes/parameters/multi_parameter.py +++ b/src/qcodes/parameters/multi_parameter.py @@ -23,7 +23,7 @@ np.ndarray, ) except ImportError: - _SP_TYPES: tuple[type, ...] = ( + _SP_TYPES = ( type(None), Sequence, Iterator, From 4f17970c311eb970e3da27f49a8df6eba538519b Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Fri, 2 Feb 2024 16:12:56 +0100 Subject: [PATCH 5/6] check with all std pyright rules except incompatible override --- pyproject.toml | 4 +++- .../Keysight/private/Keysight_344xxA_submodules.py | 2 +- src/qcodes/instrument_drivers/Minicircuits/USBHIDMixin.py | 4 ++-- src/qcodes/instrument_drivers/tektronix/AWG70000A.py | 8 +++++--- src/qcodes/utils/spyder_utils.py | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a94145ca270..89d85e4f9f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -209,7 +209,9 @@ reportMissingTypeStubs = true stubPath = "typings/stubs" # we would like to move this to at least standard # eventually. From 1.1.339 onwards standard is the default -typeCheckingMode = "basic" +typeCheckingMode = "standard" +reportIncompatibleMethodOverride = false # we have a lot of these. We should eventually enable this + [tool.pytest.ini_options] minversion = "7.2" diff --git a/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py b/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py index baaa811e346..3c3db692993 100644 --- a/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py +++ b/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py @@ -393,7 +393,7 @@ def _acquire_time_trace(self) -> np.ndarray: self.instrument.trigger.force() data = self.instrument.fetch() - return data # pyright: ignore[reportUnboundVariable] + return data # pyright: ignore[reportPossiblyUnboundVariable] def get_raw(self) -> np.ndarray: # pylint: disable=method-hidden diff --git a/src/qcodes/instrument_drivers/Minicircuits/USBHIDMixin.py b/src/qcodes/instrument_drivers/Minicircuits/USBHIDMixin.py index 1380d35ebd1..f5907ea054d 100644 --- a/src/qcodes/instrument_drivers/Minicircuits/USBHIDMixin.py +++ b/src/qcodes/instrument_drivers/Minicircuits/USBHIDMixin.py @@ -47,7 +47,7 @@ def __init__(self, name: str, instance_id: Optional[str] = None, **kwargs: Any): self._check_hid_import() - devs = hid.HidDeviceFilter( + devs = hid.HidDeviceFilter( # pyright: ignore[reportPossiblyUnboundVariable] product_id=self.product_id, vendor_id=self.vendor_id, instance_id=instance_id @@ -144,7 +144,7 @@ def enumerate_devices(cls) -> list[str]: """ cls._check_hid_import() - devs = hid.HidDeviceFilter( + devs = hid.HidDeviceFilter( # pyright: ignore[reportPossiblyUnboundVariable] porduct_id=cls.product_id, vendor_id=cls.vendor_id ).get_devices() diff --git a/src/qcodes/instrument_drivers/tektronix/AWG70000A.py b/src/qcodes/instrument_drivers/tektronix/AWG70000A.py index 6e87e92087b..bf63057c75c 100644 --- a/src/qcodes/instrument_drivers/tektronix/AWG70000A.py +++ b/src/qcodes/instrument_drivers/tektronix/AWG70000A.py @@ -493,15 +493,17 @@ def __init__( if add_channel_list: # pyright does not seem to understand # that this code can only run iff chanliss is created - chanlist.append(channel) # pyright: ignore[reportUnboundVariable] + chanlist.append( # pyright: ignore[reportPossiblyUnboundVariable] + channel + ) if add_channel_list: self.add_submodule( "channels", - chanlist.to_channel_tuple(), # pyright: ignore[reportUnboundVariable] + chanlist.to_channel_tuple(), # pyright: ignore[reportPossiblyUnboundVariable] ) - # Folder on the AWG where to files are uplaoded by default + # Folder on the AWG where to files are uploaded by default self.wfmxFileFolder = "\\Users\\OEM\\Documents" self.seqxFileFolder = "\\Users\\OEM\\Documents" diff --git a/src/qcodes/utils/spyder_utils.py b/src/qcodes/utils/spyder_utils.py index c5744865d77..f7fa14361c3 100644 --- a/src/qcodes/utils/spyder_utils.py +++ b/src/qcodes/utils/spyder_utils.py @@ -44,7 +44,7 @@ def add_to_spyder_UMR_excludelist(modulename: str) -> None: if modulename not in excludednamelist: _LOG.info(f"adding {modulename} to excluded modules") excludednamelist.append(modulename) - sitecustomize.__umr__ = sitecustomize.UserModuleReloader( # pyright: ignore[reportUnboundVariable] + sitecustomize.__umr__ = sitecustomize.UserModuleReloader( # pyright: ignore[reportPossiblyUnboundVariable] namelist=excludednamelist ) os.environ["SPY_UMR_NAMELIST"] = ",".join(excludednamelist) From 57a1850438e17c772adda33047d4baea27a84dad Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Fri, 2 Feb 2024 16:14:58 +0100 Subject: [PATCH 6/6] clarify comment --- pyproject.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 89d85e4f9f2..a72ea17ae1d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -209,8 +209,10 @@ reportMissingTypeStubs = true stubPath = "typings/stubs" # we would like to move this to at least standard # eventually. From 1.1.339 onwards standard is the default +# for now we enable all of standard except for +# incompatibleMethodOverride which we have a lot of typeCheckingMode = "standard" -reportIncompatibleMethodOverride = false # we have a lot of these. We should eventually enable this +reportIncompatibleMethodOverride = false [tool.pytest.ini_options]