diff --git a/cirq-core/cirq/study/sweeps.py b/cirq-core/cirq/study/sweeps.py index 880ee18c082..c4c41016d4e 100644 --- a/cirq-core/cirq/study/sweeps.py +++ b/cirq-core/cirq/study/sweeps.py @@ -98,10 +98,10 @@ def __add__(self, other: 'Sweep') -> 'Sweep': return Zip(*sweeps) @abc.abstractmethod - def __eq__(self, other): + def __eq__(self, other) -> bool: pass - def __ne__(self, other): + def __ne__(self, other) -> bool: return not self == other @property diff --git a/cirq-core/cirq/value/abc_alt_test.py b/cirq-core/cirq/value/abc_alt_test.py index f59947b000e..33ff9c4ce52 100644 --- a/cirq-core/cirq/value/abc_alt_test.py +++ b/cirq-core/cirq/value/abc_alt_test.py @@ -13,6 +13,8 @@ # limitations under the License. import abc +from typing import NoReturn, Optional + import pytest from cirq import ABCMetaImplementAnyOneOf, alternative @@ -21,7 +23,7 @@ def test_regular_abstract(): class RegularAbc(metaclass=ABCMetaImplementAnyOneOf): @abc.abstractmethod - def my_method(self): + def my_method(self) -> str: """Docstring.""" with pytest.raises(TypeError, match='abstract'): @@ -38,11 +40,11 @@ def my_method(self, arg, kw=99): """my_method doc.""" @abc.abstractmethod - def alt(self): + def alt(self) -> str: pass class SingleAlternativeChild(SingleAlternative): - def alt(self): + def alt(self) -> str: return 'alt' class SingleAlternativeOverride(SingleAlternative): @@ -80,22 +82,22 @@ def _default_impl(self, arg, kw=99): """Default implementation.""" @alternative(requires='alt', implementation=_default_impl) - def my_method(self, arg, kw=99): + def my_method(self, arg, kw=99) -> None: """my_method doc.""" @abc.abstractmethod - def alt(self): + def alt(self) -> None: pass class SingleAlternativeChild(SingleAlternative): - def alt(self): + def alt(self) -> None: """Alternative method.""" class SingleAlternativeOverride(SingleAlternative): - def my_method(self, arg, kw=99): + def my_method(self, arg, kw=99) -> None: """my_method override.""" - def alt(self): + def alt(self) -> None: """Unneeded alternative method.""" assert SingleAlternative.my_method.__doc__ == 'my_method doc.' @@ -151,32 +153,32 @@ def _default_impl2(self, arg, kw=99): @alternative(requires='alt1', implementation=_default_impl1) @alternative(requires='alt2', implementation=_default_impl2) - def my_method(self, arg, kw=99): + def my_method(self, arg, kw=99) -> str: """Docstring.""" @abc.abstractmethod - def alt1(self): + def alt1(self) -> Optional[str]: pass @abc.abstractmethod - def alt2(self): + def alt2(self) -> Optional[str]: pass class TwoAlternativesChild(TwoAlternatives): - def alt1(self): + def alt1(self) -> str: return 'alt1' - def alt2(self): + def alt2(self) -> NoReturn: raise RuntimeError # coverage: ignore class TwoAlternativesOverride(TwoAlternatives): - def my_method(self, arg, kw=99): + def my_method(self, arg, kw=99) -> str: return 'override' - def alt1(self): + def alt1(self) -> NoReturn: raise RuntimeError # coverage: ignore - def alt2(self): + def alt2(self) -> NoReturn: raise RuntimeError # coverage: ignore class TwoAlternativesForceSecond(TwoAlternatives): diff --git a/dev_tools/check.py b/dev_tools/check.py index e9bad9a20f0..e5d0054af6b 100644 --- a/dev_tools/check.py +++ b/dev_tools/check.py @@ -64,7 +64,7 @@ def perform_check(self, env: env_tools.PreparedEnv, verbose: bool) -> Tuple[bool A tuple containing a pass/fail boolean and then a details message. """ - def needs_python2_env(self): + def needs_python2_env(self) -> bool: return False def run(