Skip to content

Commit bf61943

Browse files
authored
Enable ruff T20 group (#15719)
One of the lints we previously had enabled in pylint was disallowing prints. This was added in #13796 to prevent us from accidently committing print debug statements which was happening fairly frequently. However, in the recently merged #15603 we migrated from pylint to use ruff and during that migration this lint was dropped. This commit corrects this oversight by enabling the ruff rule group T20 which is used to disable using print or pprint in code. One small change that this enabled was the discovery there was an unused `verbose` flag in the internal matplotlib circuit drawer APIs that was used to print every op node as it drew them. This has no real value and wasn't exposed via any public API so this commit just opts to remove the option along with the print statement.
1 parent cf806e1 commit bf61943

8 files changed

Lines changed: 13 additions & 14 deletions

File tree

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ select = [
340340
"PIE",
341341
# flake8-no-pep420
342342
"INP",
343+
# flake8-print
344+
"T20",
343345
]
344346
ignore = [
345347
"E402", # module-import-not-at-top-of-file false positives with module docs
@@ -372,6 +374,8 @@ ignore = [
372374
"*.ipynb" = ["F821"]
373375
# Security rules from bandit don't apply to tests and utils
374376
"tools/*" = [
377+
# Tools can print to stdout
378+
"T201",
375379
"S603",
376380
# Docstring rules don't apply to tools as they're not documented
377381
"D100",

qiskit/quantum_info/operators/operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def draw(self, output=None, **drawer_args):
240240
def _ipython_display_(self):
241241
out = self.draw()
242242
if isinstance(out, str):
243-
print(out)
243+
print(out) # noqa: T201
244244
else:
245245
from IPython.display import display
246246

qiskit/quantum_info/states/densitymatrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def draw(self, output: str | None = None, **drawer_args):
180180
def _ipython_display_(self):
181181
out = self.draw()
182182
if isinstance(out, str):
183-
print(out)
183+
print(out) # noqa: T201
184184
else:
185185
from IPython.display import display
186186

qiskit/quantum_info/states/statevector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def draw(self, output: str | None = None, **drawer_args):
267267
def _ipython_display_(self):
268268
out = self.draw()
269269
if isinstance(out, str):
270-
print(out)
270+
print(out) # noqa: T201
271271
else:
272272
from IPython.display import display
273273

qiskit/visualization/circuit/matplotlib.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def __init__(
252252
"}": (0.1896, 0.1188),
253253
}
254254

255-
def draw(self, filename=None, verbose=False):
255+
def draw(self, filename=None):
256256
"""Main entry point to 'matplotlib' ('mpl') drawer. Called from
257257
``visualization.circuit_drawer`` and from ``QuantumCircuit.draw`` through circuit_drawer.
258258
"""
@@ -390,7 +390,6 @@ def draw(self, filename=None, verbose=False):
390390
qubits_dict,
391391
clbits_dict,
392392
glob_data,
393-
verbose,
394393
)
395394
if filename:
396395
mpl_figure.savefig(
@@ -1080,7 +1079,6 @@ def _draw_ops(
10801079
qubits_dict,
10811080
clbits_dict,
10821081
glob_data,
1083-
verbose=False,
10841082
):
10851083
"""Draw the gates in the circuit"""
10861084

@@ -1106,9 +1104,6 @@ def _draw_ops(
11061104

11071105
self._get_colors(node, node_data)
11081106

1109-
if verbose:
1110-
print(op)
1111-
11121107
# add conditional
11131108
if getattr(op, "condition", None) or isinstance(op, SwitchCaseOp):
11141109
cond_xy = [

test/qpy_compat/get_versions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def available_versions_for_package(package, min_version=None, max_version=None):
7575
if release["packagetype"] == "bdist_wheel" and not release["yanked"]
7676
for tag in tags_from_wheel_name(release["filename"])
7777
):
78-
print(
78+
print( # noqa: T201
7979
f"skipping '{other_version}', which has no installable binary artifacts",
8080
file=sys.stderr,
8181
)
@@ -96,7 +96,7 @@ def available_versions_for_package(package, min_version=None, max_version=None):
9696
python_versions, key=lambda s: tuple(map(int, s.split(".")))
9797
)
9898
except ValueError:
99-
print(
99+
print( # noqa: T201
100100
f"skipping '{other_version}', which has no installable binary artifacts",
101101
file=sys.stderr,
102102
)
@@ -118,7 +118,7 @@ def available_versions_for_package(package, min_version=None, max_version=None):
118118
def main():
119119
"""main"""
120120
for package, version, python_version in available_versions():
121-
print(package, version, python_version)
121+
print(package, version, python_version) # noqa: T201
122122

123123

124124
if __name__ == "__main__":

test/qpy_compat/test_qpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ def load_qpy(qpy_files, version_parts):
11021102
# so not loading and comparing these payloads.
11031103
# See https://github.com/Qiskit/qiskit/pull/13814
11041104
continue
1105-
print(f"Loading qpy file: {path}")
1105+
print(f"Loading qpy file: {path}") # noqa: T201
11061106
with open(path, "rb") as fd:
11071107
qpy_circuits = load(fd)
11081108
equivalent = path in {"open_controlled_gates.qpy", "controlled_gates.qpy"}

test/randomized/test_transpiler_equivalence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def equivalent_transpile(self, kwargs):
285285
+ ", ".join(f"{key:s}={value!r}" for key, value in kwargs.items() if value is not None)
286286
+ ")"
287287
)
288-
print(f"Evaluating {call} for:\n{qasm2.dumps(self.qc)}")
288+
print(f"Evaluating {call} for:\n{qasm2.dumps(self.qc)}") # noqa: T201
289289

290290
shots = 4096
291291

0 commit comments

Comments
 (0)