diff --git a/mypy/checker.py b/mypy/checker.py index 33705c98e10c..fc6c47b8599a 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -1696,6 +1696,7 @@ def check_funcdef_item( if ( defn.info and self.is_reverse_op_method(name) + and not defn.info.is_protocol and defn not in self.overload_impl_stack ): # TODO: we should use decorated signature for this check. diff --git a/test-data/unit/check-protocols.test b/test-data/unit/check-protocols.test index 6e86507eb48d..6f381a19380e 100644 --- a/test-data/unit/check-protocols.test +++ b/test-data/unit/check-protocols.test @@ -4809,3 +4809,12 @@ bad_rep(t) # E: Argument 1 to "bad_rep" has incompatible type "C"; expected "P[ # N: Got: \ # N: def rep(self) -> C [builtins fixtures/tuple.pyi] + +[case testProtocolTernaryRpow] +from typing import Protocol + +class PowableProto(Protocol): + def __pow__(self, other: "PowableProto", modulo: "PowableProto") -> "PowableProto": + ... + def __rpow__(self, other: "PowableProto", modulo: "PowableProto") -> "PowableProto": + ...