Skip to content

Commit 40fc9ab

Browse files
authored
Fixes mypy failure with latest mypy 1.16.0 (#944)
* Fix errors raised by latest mypy (1.16.0) * fix comment * Added type ignore to avoid mypy failure * Fix date that somehow I messed up * Make ignore cover the 3.9 and > 3.9 cases * Fix lint too long line (why was black ok with it?)
1 parent c78e367 commit 40fc9ab

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

qiskit_machine_learning/gradients/lin_comb/lin_comb_estimator_gradient.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2022, 2024.
3+
# (C) Copyright IBM 2022, 2025.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -233,7 +233,9 @@ def _run_unique(
233233
gradient.imag = results[partial_sum_n + n // 2 : partial_sum_n + n]
234234

235235
else:
236-
gradient = np.real(results[partial_sum_n : partial_sum_n + n])
236+
gradient = np.real(
237+
results[partial_sum_n : partial_sum_n + n]
238+
) # type: ignore[assignment, unused-ignore]
237239
partial_sum_n += n
238240
gradients.append(gradient)
239241

qiskit_machine_learning/neural_networks/effective_dimension.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,20 @@ def __init__(
6262
"""
6363

6464
# Store arguments
65-
self._weight_samples = None
66-
self._input_samples = None
67-
self._num_weight_samples = 1
68-
self._num_input_samples = 1
65+
self._weight_samples = np.asarray([0.25])
66+
self._input_samples = np.asarray([0.5])
67+
self._num_weight_samples = len(self._weight_samples)
68+
self._num_input_samples = len(self._input_samples)
6969
self._model = qnn
7070

71-
# Define weight samples and input samples
72-
self.weight_samples = weight_samples # type: ignore
73-
# input setter uses self._model
74-
self.input_samples = input_samples # type: ignore
71+
# Setup things for weight and input samples via setters that deal
72+
# with the union of types that can be passed so that the private
73+
# vars above that have just been set with temp values of right types
74+
# to establish typing, get the right values per what was passed.
75+
# Note, the samples ones above had been set to None but this results
76+
# in errors when checking using mypy 1.16.0
77+
self.weight_samples = weight_samples
78+
self.input_samples = input_samples
7579

7680
@property
7781
def weight_samples(self) -> np.ndarray:

qiskit_machine_learning/variational_algorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2019, 2024.
3+
# (C) Copyright IBM 2019, 2025.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -91,7 +91,7 @@ def optimal_value(self) -> float | None:
9191
return self._optimal_value
9292

9393
@optimal_value.setter
94-
def optimal_value(self, value: int) -> None:
94+
def optimal_value(self, value: float) -> None:
9595
"""Sets optimal value"""
9696
self._optimal_value = value
9797

0 commit comments

Comments
 (0)