Skip to content

Commit

Permalink
Fixed mypy again
Browse files Browse the repository at this point in the history
  • Loading branch information
blakewilsonquantinuum committed Jan 7, 2025
1 parent f7d78b4 commit 062031e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions lambeq/backend/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,20 @@ def tensor(self, other: Iterable[Self]) -> Self: ...
@overload
def tensor(self, other: Self, *rest: Self) -> Self: ...

def tensor(self, other: Self | Iterable[Self], *rest: Self) -> Self | Any:
def tensor(self, other: Self | Iterable[Self], *rest: Self) -> Self:
try:
tys = [*other, *rest]
except TypeError:
return NotImplemented
raise NotImplementedError

# Diagrams are iterable - the identity diagram has
# an empty list for its layers but may still contain types
if getattr(other, 'is_id', False):
return NotImplemented
raise NotImplementedError

if any(not isinstance(ty, type(self))
or self.category != ty.category for ty in tys):
return NotImplemented
raise NotImplementedError

return self._fromiter(ob for ty in (self, *tys) for ob in ty)

Expand Down Expand Up @@ -957,11 +957,11 @@ def lift(cls, diagrams: Iterable[Diagrammable | Ty]) -> list[Self]:

return diags # type: ignore[return-value]

def tensor(self, *diagrams: Diagrammable | Ty) -> Self | Any:
def tensor(self, *diagrams: Diagrammable | Ty) -> Self:
try:
diags = self.lift([self, *diagrams])
except ValueError:
return NotImplemented
raise NotImplementedError

right = dom = self.dom.tensor(*[
diagram.to_diagram().dom for diagram in diagrams
Expand Down Expand Up @@ -1016,11 +1016,11 @@ def __getitem__(self, key: int | slice) -> Self:
return self[key:key + 1]
raise TypeError

def then(self, *diagrams: Diagrammable) -> Self | Any:
def then(self, *diagrams: Diagrammable) -> Self:
try:
diags = self.lift(diagrams)
except ValueError:
return NotImplemented
raise NotImplementedError

layers = [*self.layers]
cod = self.cod
Expand Down
2 changes: 1 addition & 1 deletion lambeq/backend/pennylane.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

from itertools import product
import sys
from typing import List, TYPE_CHECKING, Union, Set, Tuple
from typing import List, Set, Tuple, TYPE_CHECKING, Union

import pennylane as qml
import sympy
Expand Down
4 changes: 2 additions & 2 deletions lambeq/backend/pregroup_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ def __eq__(self, other: object) -> bool:
== (other.parent.ind if other.parent else None))
and self.children == other.children)

def is_same_word(self, other: object) -> bool:
def is_same_word(self, other: object) -> bool: # type : [no-any-return]
"""Check if these words are the same words in the sentence.
This is a relaxed version of the `__eq__` function
which doesn't check equality of the children - essentially,
this just checks if `other` is the same token."""
if not isinstance(other, PregroupTreeNode):
return NotImplemented
raise NotImplementedError
return (self.word == other.word
and self.ind == other.ind)

Expand Down

0 comments on commit 062031e

Please sign in to comment.