diff options
author | Nao Pross <np@0hm.ch> | 2024-04-25 17:28:23 +0200 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-04-25 17:28:23 +0200 |
commit | 75e428c6337b22fe14f8f8394c8e21dee2d857db (patch) | |
tree | 3def79d68afa862dd2c82dff24cae86e471f74a5 | |
parent | Fix incorrect behaviour of init_variable_expr (diff) | |
download | polymatrix-75e428c6337b22fe14f8f8394c8e21dee2d857db.tar.gz polymatrix-75e428c6337b22fe14f8f8394c8e21dee2d857db.zip |
Add __repr__ methods to some polymatrix.typing classes
Diffstat (limited to '')
-rw-r--r-- | polymatrix/polymatrix/typing.py | 15 |
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() + + |