Skip to content

Commit 83b8ddf

Browse files
committed
Revert "Add ruff rule UP031 Use format specifiers instead of percent format"
This reverts commit 2863fd4. The reason for making these changes is not clear. A desired policy for formatting should be decided if we want to enforce a rule.
1 parent cb725b0 commit 83b8ddf

File tree

15 files changed

+31
-35
lines changed

15 files changed

+31
-35
lines changed

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ select = [
5252
"UP018", # Unnecessary call to `bytes`. (Using b'' instead of bytes() is much faster)
5353
"UP034", # Avoid extraneous parentheses
5454
"UP032", # Use f-string instead of format call
55-
"UP031", # Use format specifiers instead of percent format
5655
"YTT", # misuse of sys.version or sys.version_info
5756
"C4", # flake8-comprehensions, several rules
5857
"DTZ003", # use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead

qiskit/circuit/library/data_preparation/state_preparation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ def _define_from_int(self):
145145
# Raise if number of bits is greater than num_qubits
146146
if len(intstr) > self.num_qubits:
147147
raise QiskitError(
148-
"StatePreparation integer has {} bits, but this exceeds the"
149-
" number of qubits in the circuit, {}.".format(len(intstr), self.num_qubits)
148+
"StatePreparation integer has %s bits, but this exceeds the"
149+
" number of qubits in the circuit, %s." % (len(intstr), self.num_qubits)
150150
)
151151

152152
for qubit, bit in enumerate(intstr):

qiskit/circuit/quantumcircuit.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ def __init__(
239239

240240
if not valid_reg_size:
241241
raise CircuitError(
242-
"Circuit args must be Registers or integers. ({} '{}' was "
243-
"provided)".format([type(reg).__name__ for reg in regs], regs)
242+
"Circuit args must be Registers or integers. (%s '%s' was "
243+
"provided)" % ([type(reg).__name__ for reg in regs], regs)
244244
)
245245

246246
regs = tuple(int(reg) for reg in regs) # cast to int
@@ -1385,7 +1385,7 @@ def add_register(self, *regs: Union[Register, int, Sequence[Bit]]) -> None:
13851385
raise CircuitError(
13861386
"QuantumCircuit parameters can be Registers or Integers."
13871387
" If Integers, up to 2 arguments. QuantumCircuit was called"
1388-
" with {}.".format(regs)
1388+
" with %s." % (regs,)
13891389
)
13901390

13911391
for register in regs:

qiskit/circuit/register.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(self, size=None, name=None, bits=None):
8080
if (size, bits) == (None, None) or (size is not None and bits is not None):
8181
raise CircuitError(
8282
"Exactly one of the size or bits arguments can be "
83-
"provided. Provided size={} bits={}.".format(size, bits)
83+
"provided. Provided size=%s bits=%s." % (size, bits)
8484
)
8585

8686
# validate (or cast) size

qiskit/compiler/assembler.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ def _parse_common_args(
326326
raise QiskitError("Argument 'shots' should be of type 'int'")
327327
elif max_shots and max_shots < shots:
328328
raise QiskitError(
329-
"Number of shots specified: {} exceeds max_shots property of the "
330-
"backend: {}.".format(shots, max_shots)
329+
"Number of shots specified: %s exceeds max_shots property of the "
330+
"backend: %s." % (shots, max_shots)
331331
)
332332

333333
dynamic_reprate_enabled = getattr(backend_config, "dynamic_reprate_enabled", False)

qiskit/qpy/interface.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ def load(
248248
):
249249
warnings.warn(
250250
"The qiskit version used to generate the provided QPY "
251-
"file, {}, is newer than the current qiskit version {}. "
251+
"file, %s, is newer than the current qiskit version %s. "
252252
"This may result in an error if the QPY file uses "
253253
"instructions not present in this current qiskit "
254-
"version".format(".".join([str(x) for x in qiskit_version]), __version__)
254+
"version" % (".".join([str(x) for x in qiskit_version]), __version__)
255255
)
256256

257257
if data.qpy_version < 5:

qiskit/test/base.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,21 @@ def setUp(self):
7979
super().setUp()
8080
if self.__setup_called:
8181
raise ValueError(
82-
"In File: {}\n"
82+
"In File: %s\n"
8383
"TestCase.setUp was already called. Do not explicitly call "
8484
"setUp from your tests. In your own setUp, use super to call "
85-
"the base setUp.".format(sys.modules[self.__class__.__module__].__file__)
85+
"the base setUp." % (sys.modules[self.__class__.__module__].__file__,)
8686
)
8787
self.__setup_called = True
8888

8989
def tearDown(self):
9090
super().tearDown()
9191
if self.__teardown_called:
9292
raise ValueError(
93-
"In File: {}\n"
93+
"In File: %s\n"
9494
"TestCase.tearDown was already called. Do not explicitly call "
9595
"tearDown from your tests. In your own tearDown, use super to "
96-
"call the base tearDown.".format(sys.modules[self.__class__.__module__].__file__)
96+
"call the base tearDown." % (sys.modules[self.__class__.__module__].__file__,)
9797
)
9898
self.__teardown_called = True
9999

qiskit/transpiler/layout.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ def order_based_on_type(value1, value2):
9797
virtual = value1
9898
else:
9999
raise LayoutError(
100-
"The map ({} -> {}) has to be a (Bit -> integer)"
101-
" or the other way around.".format(type(value1), type(value2))
100+
"The map (%s -> %s) has to be a (Bit -> integer)"
101+
" or the other way around." % (type(value1), type(value2))
102102
)
103103
return virtual, physical
104104

@@ -136,7 +136,7 @@ def __delitem__(self, key):
136136
else:
137137
raise LayoutError(
138138
"The key to remove should be of the form"
139-
" Qubit or integer) and {} was provided".format(type(key))
139+
" Qubit or integer) and %s was provided" % (type(key),)
140140
)
141141

142142
def __len__(self):

qiskit/transpiler/passes/basis/unroll_custom_definitions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ def run(self, dag):
100100

101101
# opaque node
102102
raise QiskitError(
103-
"Cannot unroll the circuit to the given basis, {}. "
104-
"Instruction {} not found in equivalence library "
105-
"and no rule found to expand.".format(str(self._basis_gates), node.op.name)
103+
"Cannot unroll the circuit to the given basis, %s. "
104+
"Instruction %s not found in equivalence library "
105+
"and no rule found to expand." % (str(self._basis_gates), node.op.name)
106106
)
107107
decomposition = circuit_to_dag(node.op.definition)
108108
unrolled_dag = UnrollCustomDefinitions(

qiskit/transpiler/passes/basis/unroller.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ def run(self, dag):
134134
continue
135135
# opaque node
136136
raise QiskitError(
137-
"Cannot unroll the circuit to the given basis, {}. "
138-
"No rule to expand instruction {}.".format(str(self.basis), node.op.name)
137+
"Cannot unroll the circuit to the given basis, %s. "
138+
"No rule to expand instruction %s." % (str(self.basis), node.op.name)
139139
)
140140
decomposition = circuit_to_dag(node.op.definition)
141141
unrolled_dag = self.run(decomposition) # recursively unroll ops

qiskit/transpiler/runningpassmanager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def _run_this_pass(self, pass_, dag):
218218
else:
219219
raise TranspilerError(
220220
"Transformation passes should return a transformed dag."
221-
"The pass {} is returning a {}".format(type(pass_).__name__, type(new_dag))
221+
"The pass %s is returning a %s" % (type(pass_).__name__, type(new_dag))
222222
)
223223
dag = new_dag
224224
elif pass_.is_analysis_pass:

qiskit/visualization/circuit/latex.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,7 @@ def _build_measure(self, node, col):
591591
else:
592592
wire2 = self._wire_map[node.cargs[0]]
593593

594-
self._latex[wire2][
595-
col
596-
] = "\\dstick{{_{{_{{\\hspace{{{}em}}{}}}}}}} \\cw \\ar @{{<=}} [-{},0]".format(
594+
self._latex[wire2][col] = "\\dstick{_{_{\\hspace{%sem}%s}}} \\cw \\ar @{<=} [-%s,0]" % (
597595
cond_offset,
598596
idx_str,
599597
str(wire2 - wire1),
@@ -664,9 +662,7 @@ def _add_condition(self, op, wire_list, col):
664662
)
665663
gap = cwire - max(wire_list)
666664
control = "\\control" if op.condition[1] else "\\controlo"
667-
self._latex[cwire][
668-
col
669-
] = f"{control}" + " \\cw^({}){{^{{\\mathtt{{{}}}}}}} \\cwx[-{}]".format(
665+
self._latex[cwire][col] = f"{control}" + " \\cw^(%s){^{\\mathtt{%s}}} \\cwx[-%s]" % (
670666
meas_offset,
671667
label,
672668
str(gap),

qiskit/visualization/counts_visualization.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ def _plotting_core(
287287

288288
if legend and len(legend) != len(data):
289289
raise VisualizationError(
290-
f"Length of legend ({len(legend)}) doesn't match number of input executions ({len(data)})."
290+
"Length of legend (%s) doesn't match "
291+
"number of input executions: %s" % (len(legend), len(data))
291292
)
292293

293294
# Set bar colors

test/ipynb/results.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ def _repr_html_(self):
185185
)
186186
else:
187187
title = (
188-
'Download <a download="{}" href="{}">this image</a> to <tt>{}</tt>'
189-
" and add/push to the repo</td>".format(name, fullpath_name, fullpath_reference)
188+
'Download <a download="%s" href="%s">this image</a> to <tt>%s</tt>'
189+
" and add/push to the repo</td>" % (name, fullpath_name, fullpath_reference)
190190
)
191191
ret += Results.no_reference_html(fullpath_name, title)
192192
ret += "</div>"

test/python/basicaer/test_basicaer_backends.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def _get_first_available_backend(provider, backend_names):
4141
deprecated_names = BasicAer._deprecated_backend_names()
4242
for oldname, newname in deprecated_names.items():
4343
expected = (
44-
"WARNING:qiskit.providers.providerutils:Backend '{}' is deprecated. "
45-
"Use '{}'.".format(oldname, newname)
44+
"WARNING:qiskit.providers.providerutils:Backend '%s' is deprecated. "
45+
"Use '%s'." % (oldname, newname)
4646
)
4747
with self.subTest(oldname=oldname, newname=newname):
4848
with self.assertLogs("qiskit.providers.providerutils", level="WARNING") as context:

0 commit comments

Comments
 (0)