Skip to content

Commit

Permalink
Merge pull request #5659 from jenshnielsen/pyright_344
Browse files Browse the repository at this point in the history
Upgrade pyright to 1.1.349
  • Loading branch information
jenshnielsen authored Feb 5, 2024
2 parents dd89f7c + 57a1850 commit 7e61922
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
if: ${{ !matrix.min-version }}
- uses: jakebailey/pyright-action@03ab3c98073356eb56161009632b39fc2666321b # v2.0.1
with:
version: 1.1.339
version: 1.1.349
if: ${{ !matrix.min-version }}
- name: Run Mypy
run: mypy -p qcodes
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ reportDeprecated = 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"
# for now we enable all of standard except for
# incompatibleMethodOverride which we have a lot of
typeCheckingMode = "standard"
reportIncompatibleMethodOverride = false


[tool.pytest.ini_options]
minversion = "7.2"
Expand Down
4 changes: 1 addition & 3 deletions src/qcodes/dataset/sqlite/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/qcodes/instrument_drivers/Keithley/_Keithley_2600.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/qcodes/instrument_drivers/Minicircuits/USBHIDMixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 5 additions & 3 deletions src/qcodes/instrument_drivers/tektronix/AWG70000A.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
36 changes: 20 additions & 16 deletions src/qcodes/parameters/array_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
type(None),
collections.abc.Sequence,
collections.abc.Iterator,
np.ndarray,
)


class ArrayParameter(ParameterBase):
"""
A gettable parameter that returns an array of values.
Expand Down Expand Up @@ -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(
Expand Down
43 changes: 19 additions & 24 deletions src/qcodes/parameters/multi_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
type(None),
Sequence,
Iterator,
np.ndarray,
)


def _is_nested_sequence_or_none(
obj: Any,
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/qcodes/sphinx_extensions/parse_parameter_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions src/qcodes/utils/deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/qcodes/utils/spyder_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 7e61922

Please sign in to comment.