Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix raiser is not callable. #5155

Merged
merged 4 commits into from
Mar 28, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Better fix.
  • Loading branch information
MichaelBroughton committed Mar 28, 2022
commit 9d106caaa98f937582023b8743affda283b20adc
8 changes: 4 additions & 4 deletions cirq-core/cirq/protocols/pow_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, overload, TYPE_CHECKING, TypeVar, Union
from typing import Any, cast, overload, TYPE_CHECKING, TypeVar, Union, Callable

if TYPE_CHECKING:
import cirq
Expand All @@ -24,7 +24,7 @@
TDefault = TypeVar('TDefault')


# pylint: disable=function-redefined, redefined-builtin, not-callable
# pylint: disable=function-redefined, redefined-builtin
@overload
def pow(val: 'cirq.Gate', exponent: Any) -> 'cirq.Gate':
pass
Expand Down Expand Up @@ -81,7 +81,7 @@ def pow(val: Any, exponent: Any, default: Any = RaiseTypeErrorIfNotProvided) ->
TypeError: `val` doesn't have a __pow__ method (or that method returned
NotImplemented) and no `default` value was specified.
"""
raiser = getattr(val, '__pow__', None)
raiser = cast(Union[None, Callable], getattr(val, '__pow__', None))
result = NotImplemented if raiser is None else raiser(exponent)
if result is not NotImplemented:
return result
Expand All @@ -96,4 +96,4 @@ def pow(val: Any, exponent: Any, default: Any = RaiseTypeErrorIfNotProvided) ->
)


# pylint: enable=function-redefined, redefined-builtin, not-callable
# pylint: enable=function-redefined, redefined-builtin