Skip to content

Commit 4a39b42

Browse files
micpap25mpharrigan
andauthored
Correct lint issues exposed with update to pylint-3 (#1652)
Fixes #1440 Re-enables the following pylint issues which were disabled when bumping to pylint-3. - [x] abstract-class-instantiated - [X] deprecated-class - [x] possibly-used-before-assignment - [x] used-before-assignment --------- Co-authored-by: Matthew Harrigan <mpharrigan@google.com>
1 parent 1087510 commit 4a39b42

6 files changed

Lines changed: 24 additions & 17 deletions

File tree

dev_tools/conf/.pylintrc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ score=no
77
reports=no
88
py-version=3.9
99
disable=
10-
abstract-class-instantiated, # TODO: #1440 - enable and fix
11-
deprecated-class, # TODO: #1440 - enable and fix
12-
possibly-used-before-assignment, # TODO: #1440 - enable and fix
13-
used-before-assignment, # TODO: #1440 - enable and fix
1410
C,
1511
R,
1612
missing-raises-doc,
@@ -19,15 +15,16 @@ disable=
1915
unused-argument,
2016
fixme,
2117
unspecified-encoding,
22-
not-an-iterable, # buggy with attrs
23-
unsubscriptable-object, # buggy with attrs
24-
not-callable, # buggy with attrs
25-
no-member, # buggy with attrs
26-
reimported, # often relevant for 'autodoc' functionality
27-
import-self, # often relevant for 'autodoc' functionality
28-
redefined-outer-name, # tiggered by re-importing
29-
abstract-method, # cirq's @value.alternative not respected
30-
protected-access, # a lot of usages in tests
18+
abstract-class-instantiated, # buggy with attrs
19+
not-an-iterable, # buggy with attrs
20+
unsubscriptable-object, # buggy with attrs
21+
not-callable, # buggy with attrs
22+
no-member, # buggy with attrs
23+
reimported, # often relevant for 'autodoc' functionality
24+
import-self, # often relevant for 'autodoc' functionality
25+
redefined-outer-name, # triggered by re-importing
26+
abstract-method, # cirq's @value.alternative not respected
27+
protected-access, # a lot of usages in tests
3128
redundant-returns-doc
3229
enable=
3330
wrong-or-nonexistent-copyright-notice

qualtran/_infra/composite_bloq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
# limitations under the License.
1414

1515
"""Classes for building and manipulating `CompositeBloq`."""
16+
from collections.abc import Hashable
1617
from functools import cached_property
1718
from typing import (
1819
Callable,
1920
cast,
2021
Dict,
2122
FrozenSet,
22-
Hashable,
2323
Iterable,
2424
Iterator,
2525
List,

qualtran/bloqs/block_encoding/product.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ def build_composite_bloq(
227227
# set corresponding flag if ancillas are all zero
228228
if u.ancilla_bitsize > 0 and n - 1 > 0 and i != n - 1:
229229
controls = bb.split(cast(Soquet, anc_soq))
230+
# flag_bits_soq will always be assigned based on the following assertion
231+
assert self.ancilla_bitsize > 0
232+
# pylint: disable=used-before-assignment
230233
controls[: u.ancilla_bitsize], flag_bits_soq[i] = bb.add_t(
231234
MultiControlX(tuple([0] * u.ancilla_bitsize)),
232235
controls=controls[: u.ancilla_bitsize],

qualtran/bloqs/block_encoding/tensor_product.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,11 @@ def build_composite_bloq(
148148
for u in self.block_encodings:
149149
u_soqs = dict()
150150
u_soqs["system"] = sys_out_regs[sys_i]
151-
if "ancilla" in u.signature._lefts:
151+
# restatement of nonzero anc / res lengths prevent a
152+
# "possibly-used-before-assignment" warning from pylint
153+
if "ancilla" in u.signature._lefts and len(anc_regs) > 0:
152154
u_soqs["ancilla"] = anc_out_regs[anc_i]
153-
if "resource" in u.signature._lefts:
155+
if "resource" in u.signature._lefts and len(res_regs) > 0:
154156
u_soqs["resource"] = res_out_regs[res_i]
155157
u_soqs_out = bb.add_d(u, **u_soqs)
156158
sys_out_regs[sys_i] = u_soqs_out["system"]

qualtran/bloqs/reflections/reflection_using_prepare_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ def test_reflection_using_prepare(num_ones, eps, global_phase):
135135
signs = '-' * num_ones + '+' * (9 - num_ones)
136136
elif np.sign(global_phase) == -1:
137137
signs = '+' * num_ones + '-' * (9 - num_ones)
138+
else:
139+
raise ValueError(
140+
"sign function has failed to return 1 or -1. This may be due to nan or complex input."
141+
)
138142
assert cirq.dirac_notation(prepared_state) == get_3q_uniform_dirac_notation(signs, global_phase)
139143

140144

qualtran/symbolics/types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import overload, Sized, TypeVar, Union
14+
from collections.abc import Sized
15+
from typing import overload, TypeVar, Union
1516

1617
import numpy as np
1718
import sympy

0 commit comments

Comments
 (0)