12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
- # TODO(#6171): enable the check and fix pylint errors
16
- # pylint: disable=consider-using-f-string
17
-
18
15
import functools
19
16
import operator
20
17
from typing import Any , Callable , cast , Dict , Iterable , List , Optional , Union , TYPE_CHECKING
@@ -86,16 +83,15 @@ def __init__(
86
83
def _validate_args (self , args : List [List [ops .Qid ]], lineno : int ):
87
84
if len (args ) != self .num_args :
88
85
raise QasmException (
89
- "{ } only takes {} arg(s) (qubits and/or registers), "
90
- "got: {}, at line {}" . format ( self . qasm_gate , self . num_args , len ( args ), lineno )
86
+ f" { self . qasm_gate } only takes { self . num_args } arg(s) (qubits and/or registers), "
87
+ f "got: { len ( args ) } , at line { lineno } "
91
88
)
92
89
93
90
def _validate_params (self , params : List [float ], lineno : int ):
94
91
if len (params ) != self .num_params :
95
92
raise QasmException (
96
- "{} takes {} parameter(s), got: {}, at line {}" .format (
97
- self .qasm_gate , self .num_params , len (params ), lineno
98
- )
93
+ f"{ self .qasm_gate } takes { self .num_params } parameter(s), "
94
+ f"got: { len (params )} , at line { lineno } "
99
95
)
100
96
101
97
def on (
@@ -291,8 +287,7 @@ def p_format(self, p):
291
287
"""format : FORMAT_SPEC"""
292
288
if p [1 ] != "2.0" :
293
289
raise QasmException (
294
- "Unsupported OpenQASM version: {}, "
295
- "only 2.0 is supported currently by Cirq" .format (p [1 ])
290
+ f"Unsupported OpenQASM version: { p [1 ]} , only 2.0 is supported currently by Cirq"
296
291
)
297
292
298
293
# circuit : new_reg circuit
@@ -349,11 +344,8 @@ def _resolve_gate_operation(
349
344
):
350
345
gate_set = self .basic_gates if not self .qelibinc else self .all_gates
351
346
if gate not in gate_set .keys ():
352
- msg = 'Unknown gate "{}" at line {}{}' .format (
353
- gate ,
354
- p .lineno (1 ),
355
- ", did you forget to include qelib1.inc?" if not self .qelibinc else "" ,
356
- )
347
+ tip = ", did you forget to include qelib1.inc?" if not self .qelibinc else ""
348
+ msg = f'Unknown gate "{ gate } " at line { p .lineno (1 )} { tip } '
357
349
raise QasmException (msg )
358
350
p [0 ] = gate_set [gate ].on (args = args , params = params , lineno = p .lineno (1 ))
359
351
@@ -464,9 +456,9 @@ def p_quantum_arg_bit(self, p):
464
456
size = self .qregs [reg ]
465
457
if idx >= size :
466
458
raise QasmException (
467
- 'Out of bounds qubit index {} '
468
- 'on register {} of size {} '
469
- 'at line {}' . format ( idx , reg , size , p .lineno (1 ))
459
+ f 'Out of bounds qubit index { idx } '
460
+ f 'on register { reg } of size { size } '
461
+ f 'at line { p .lineno (1 )} '
470
462
)
471
463
if arg_name not in self .qubits .keys ():
472
464
self .qubits [arg_name ] = NamedQubit (arg_name )
@@ -483,9 +475,9 @@ def p_classical_arg_bit(self, p):
483
475
size = self .cregs [reg ]
484
476
if idx >= size :
485
477
raise QasmException (
486
- 'Out of bounds bit index {} '
487
- 'on classical register {} of size {} '
488
- 'at line {}' . format ( idx , reg , size , p .lineno (1 ))
478
+ f 'Out of bounds bit index { idx } '
479
+ f 'on classical register { reg } of size { size } '
480
+ f 'at line { p .lineno (1 )} '
489
481
)
490
482
p [0 ] = [arg_name ]
491
483
@@ -499,8 +491,8 @@ def p_measurement(self, p):
499
491
500
492
if len (qreg ) != len (creg ):
501
493
raise QasmException (
502
- 'mismatched register sizes {} -> {} for measurement '
503
- 'at line {}' . format ( len ( qreg ), len ( creg ), p .lineno (1 ))
494
+ f 'mismatched register sizes { len ( qreg ) } -> { len ( creg ) } for measurement '
495
+ f 'at line { p .lineno (1 )} '
504
496
)
505
497
506
498
p [0 ] = [
0 commit comments