From 3c89d7a13de22ec1fe26d685810a1d9543b83d34 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sun, 3 Mar 2024 14:22:03 +0100 Subject: Disallow indexing of non-variables in state --- mdpoly/state.py | 4 ++++ 1 file changed, 4 insertions(+) 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 -- cgit v1.2.1