aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-03-02 18:15:31 +0100
committerNao Pross <np@0hm.ch>2024-03-02 18:15:31 +0100
commit2a2d355dccf2fc7b855ef00c89c7888a816903b5 (patch)
treea3d857402ce2fd2bfc251b540c8f94e45d56f33d
parentFix bug in SparseRepr.terms (diff)
downloadmdpoly-2a2d355dccf2fc7b855ef00c89c7888a816903b5.tar.gz
mdpoly-2a2d355dccf2fc7b855ef00c89c7888a816903b5.zip
Rewrite state type annotations to avoid circular import
-rw-r--r--mdpoly/state.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/mdpoly/state.py b/mdpoly/state.py
index 56cd7e0..1ba44fe 100644
--- a/mdpoly/state.py
+++ b/mdpoly/state.py
@@ -1,18 +1,18 @@
-from .types import Number
-from .leaves import Var, Param
+from __future__ import annotations
+from typing import TYPE_CHECKING
-from typing import NewType
+if TYPE_CHECKING:
+ from .types import Number
+ from .leaves import Var, Param
-Index = NewType('Index', int)
-class State:
- variables: dict[Var, Index]
- parameters: dict[Param, Number]
+Index = int
+
- def __init__(self, variables, parameters={}):
- self._last_index = 0
- self.variables = variables
- self.parameters = parameters
+class State:
+ variables: dict[Var, Index] = {}
+ parameters: dict[Param, Number] = {}
+ _last_index: Index = -1
def _make_index(self) -> Index:
""" Make a new index """
@@ -27,6 +27,7 @@ class State:
return new_index
return self.variables[var]
+