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

Fixed type annotations in _BaseLineQid and _BaseGridQid #6043

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions cirq-core/cirq/devices/grid_qubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import functools
from typing import Any, Dict, Iterable, List, Optional, Tuple, Set, TypeVar, TYPE_CHECKING
from typing import Any, Dict, Iterable, List, Optional, Tuple, Set, TypeVar, TYPE_CHECKING, Union

import abc

Expand Down Expand Up @@ -75,7 +75,7 @@ def _with_row_col(self: TSelf, row: int, col: int) -> TSelf:
def __complex__(self) -> complex:
return self.col + 1j * self.row

def __add__(self: TSelf, other: Tuple[int, int]) -> 'TSelf':
def __add__(self: TSelf, other: Union[Tuple[int, int], TSelf]) -> 'TSelf':
if isinstance(other, _BaseGridQid):
if self.dimension != other.dimension:
raise TypeError(
Expand All @@ -94,7 +94,7 @@ def __add__(self: TSelf, other: Tuple[int, int]) -> 'TSelf':
)
return self._with_row_col(row=self.row + other[0], col=self.col + other[1])

def __sub__(self: TSelf, other: Tuple[int, int]) -> 'TSelf':
def __sub__(self: TSelf, other: Union[Tuple[int, int], TSelf]) -> 'TSelf':
if isinstance(other, _BaseGridQid):
if self.dimension != other.dimension:
raise TypeError(
Expand Down
6 changes: 3 additions & 3 deletions cirq-core/cirq/devices/line_qubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import functools
from typing import Any, Dict, Iterable, List, Optional, Sequence, Set, TypeVar, TYPE_CHECKING
from typing import Any, Dict, Iterable, List, Optional, Sequence, Set, TypeVar, TYPE_CHECKING, Union

import abc

Expand Down Expand Up @@ -69,7 +69,7 @@ def neighbors(self, qids: Optional[Iterable[ops.Qid]] = None) -> Set['_BaseLineQ
def _with_x(self: TSelf, x: int) -> TSelf:
"""Returns a qubit with the same type but a different value of `x`."""

def __add__(self: TSelf, other: int) -> TSelf:
def __add__(self: TSelf, other: Union[int, TSelf]) -> TSelf:
if isinstance(other, _BaseLineQid):
if self.dimension != other.dimension:
raise TypeError(
Expand All @@ -81,7 +81,7 @@ def __add__(self: TSelf, other: int) -> TSelf:
raise TypeError(f"Can only add ints and {type(self).__name__}. Instead was {other}")
return self._with_x(self.x + other)

def __sub__(self: TSelf, other: int) -> TSelf:
def __sub__(self: TSelf, other: Union[int, TSelf]) -> TSelf:
if isinstance(other, _BaseLineQid):
if self.dimension != other.dimension:
raise TypeError(
Expand Down