aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-03-03 14:22:03 +0100
committerNao Pross <np@0hm.ch>2024-03-03 14:22:03 +0100
commit3c89d7a13de22ec1fe26d685810a1d9543b83d34 (patch)
treed73375a641b8718f9e6a158a93b0460874f458dd
parentSetup Sphinx documentation generator (diff)
downloadmdpoly-3c89d7a13de22ec1fe26d685810a1d9543b83d34.tar.gz
mdpoly-3c89d7a13de22ec1fe26d685810a1d9543b83d34.zip
Disallow indexing of non-variables in state
Diffstat (limited to '')
-rw-r--r--mdpoly/state.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/mdpoly/state.py b/mdpoly/state.py
index 001d9b6..f22d502 100644
--- a/mdpoly/state.py
+++ b/mdpoly/state.py
@@ -22,6 +22,10 @@ class State:
def index(self, var: Var) -> Index:
""" Get the index for a variable. """
+ from .leaves import Var
+ if not isinstance(var, Var):
+ raise IndexError(f"Only variables (type {Var}) can be indexed.")
+
if var not in self.variables.keys():
new_index = self._make_index()
self.variables[var] = new_index