From d9309f44ed09f25ca9edd318a97160b0196be3fa Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Wed, 6 Mar 2024 11:57:30 +0100 Subject: Replace Protocols with ABC in mdpoly.abc --- mdpoly/abc.py | 23 ++++++++++++++--------- 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) -- cgit v1.2.1