Skip to content

Commit e395921

Browse files
authored
Cirq Exponent exception for str only (#7422)
Addresses request by @NoureldinYosri in #7400 .
1 parent ef6a3ab commit e395921

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

cirq-core/cirq/ops/eigen_gate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ def __init__(
107107
ValueError: If the supplied exponent is a complex number with an
108108
imaginary component.
109109
"""
110-
if not isinstance(exponent, (numbers.Number, sympy.Expr)):
110+
if isinstance(exponent, str):
111111
raise TypeError(
112112
"Gate exponent must be a number or sympy expression. "
113-
f"Invalid type: {type(exponent).__name__!r}"
113+
f"Received a string instead: {exponent!r}"
114114
)
115115
if isinstance(exponent, complex):
116116
if exponent.imag:
@@ -293,10 +293,10 @@ def _period(self) -> float | None:
293293
return _approximate_common_period(real_periods)
294294

295295
def __pow__(self, exponent: value.TParamVal) -> EigenGate:
296-
if not isinstance(exponent, (numbers.Number, sympy.Expr)):
296+
if isinstance(exponent, str):
297297
raise TypeError(
298298
"Gate exponent must be a number or sympy expression. "
299-
f"Invalid type: {type(exponent).__name__!r}"
299+
f"Received a string instead: {exponent!r}"
300300
)
301301
new_exponent = protocols.mul(self._exponent, exponent, NotImplemented)
302302
if new_exponent is NotImplemented:

0 commit comments

Comments
 (0)