summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--polymatrix/polymatrix/typing.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/polymatrix/polymatrix/typing.py b/polymatrix/polymatrix/typing.py
index 50f3f52..06b65cd 100644
--- a/polymatrix/polymatrix/typing.py
+++ b/polymatrix/polymatrix/typing.py
@@ -112,6 +112,9 @@ class PolyDict(UserDict[MonomialIndex, int | float]):
def empty() -> PolyDict:
return PolyDict({})
+ def __repr__(self):
+ return f"{self.__class__.__qualname__}({super().__repr__()})"
+
def __getitem__(self, key: Iterable[VariableIndex] | MonomialIndex) -> int | float:
if not isinstance(key, MonomialIndex):
key = MonomialIndex(key)
@@ -151,10 +154,15 @@ class PolyMatrixDict(UserDict[MatrixIndex, PolyDict]):
def empty() -> PolyMatrixDict:
return PolyMatrixDict({})
+ def __repr__(self):
+ return f"{self.__class__.__qualname__}({super().__repr__()})"
+
def __getitem__(self, key: tuple[int, int] | MatrixIndex) -> PolyDict:
if not isinstance(key, MatrixIndex):
key = MatrixIndex(*key)
- return super().__getitem__(key)
+
+ value = super().__getitem__(key)
+ return value
def __setitem__(self, key: tuple[int, int] | MatrixIndex, value: dict | PolyDict):
if not isinstance(key, MatrixIndex):
@@ -164,3 +172,8 @@ class PolyMatrixDict(UserDict[MatrixIndex, PolyDict]):
value = PolyDict(value)
return super().__setitem__(key, value)
+
+ def entries(self) -> Iterable[tuple[MatrixIndex, PolyDict]]:
+ yield from self.items()
+
+