diff options
author | Nao Pross <np@0hm.ch> | 2024-03-06 11:57:30 +0100 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-03-06 11:57:30 +0100 |
commit | d9309f44ed09f25ca9edd318a97160b0196be3fa (patch) | |
tree | 4a8853c765eb95b1ffa0e467b3c81e810e5849ae | |
parent | Improve docstring (diff) | |
download | mdpoly-d9309f44ed09f25ca9edd318a97160b0196be3fa.tar.gz mdpoly-d9309f44ed09f25ca9edd318a97160b0196be3fa.zip |
Replace Protocols with ABC in mdpoly.abc
-rw-r--r-- | mdpoly/abc.py | 23 | ||||
-rw-r--r-- | mdpoly/algebra.py | 2 |
2 files changed, 15 insertions, 10 deletions
diff --git a/mdpoly/abc.py b/mdpoly/abc.py index c503029..811910b 100644 --- a/mdpoly/abc.py +++ b/mdpoly/abc.py @@ -4,21 +4,26 @@ from .types import Number, Shape, MatrixIndex, PolyIndex from .constants import NUMERICS_EPS from .util import iszero -from typing import Self, Iterable, Sequence, Protocol, runtime_checkable -from abc import abstractmethod +from typing import Self, Iterable, Sequence, Protocol +from abc import ABC, abstractmethod -@runtime_checkable -class Leaf(Protocol): +class Leaf(ABC): """ Leaf of the binary tree. """ name: str shape: Shape -class Expr(Protocol): +class Expr(ABC): """ Binary tree to represent a mathematical expression. """ - left: Self | Leaf - right: Self | Leaf + + @property + @abstractmethod + def left(self) -> Self | Leaf: ... + + @property + @abstractmethod + def right(self) -> Self | Leaf: ... @property @abstractmethod @@ -97,13 +102,13 @@ class Expr(Protocol): yield from self.children() -class Rel(Protocol): +class Rel(ABC): """ Relation between two expressions. """ lhs: Expr rhs: Expr -class Repr(Protocol): +class Repr(ABC): r""" Representation of a multivariate matrix polynomial expression. Concretely, a representation must be able to store a mathematical object diff --git a/mdpoly/algebra.py b/mdpoly/algebra.py index 670b537..abd15d5 100644 --- a/mdpoly/algebra.py +++ b/mdpoly/algebra.py @@ -73,7 +73,7 @@ class AlgebraicStructure(Protocol): # f"objects with different shapes {cls.shape} and {other.shape}") -class ReducibleExpr(Expr, Protocol): +class ReducibleExpr(HasRepr, Protocol): """ Reducible Expression Algebraic expression that can be written in terms of other (existing) |