summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-04-16 19:33:02 +0200
committerNao Pross <np@0hm.ch>2024-04-16 19:33:02 +0200
commitf0da882517ed28c0e1759349709b3173976d5305 (patch)
tree3e25aecdc28b1e8086bf8ad538895286e48b423b
parentAdd helper methods to index types, make indexing more flexible. (diff)
downloadpolymatrix-f0da882517ed28c0e1759349709b3173976d5305.tar.gz
polymatrix-f0da882517ed28c0e1759349709b3173976d5305.zip
Fix typing problem in ExpressionStateMixin
-rw-r--r--polymatrix/expressionstate/mixins.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/polymatrix/expressionstate/mixins.py b/polymatrix/expressionstate/mixins.py
index ffaea0a..99b2cb1 100644
--- a/polymatrix/expressionstate/mixins.py
+++ b/polymatrix/expressionstate/mixins.py
@@ -2,7 +2,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from abc import abstractmethod
-from typing import NamedTuple
+from typing import NamedTuple, cast
from math import prod
import dataclasses
@@ -42,8 +42,13 @@ class ExpressionStateMixin(
size = prod(var.shape)
index = IndexRange(start=self.n_variables, end=self.n_variables + size)
- return dataclasses.replace( # type: ignore[type-var]
- self,
+ # FIXME: this is the only way the typechecker is happy, and it does
+ # make sense indeed because ExpressionState is not a dataclass
+ # The typechecker should be somehow informed that this is an ABC that
+ # will eventually become a dataclass, but of course it can't know that
+ from .impl import ExpressionStateImpl
+ return dataclasses.replace(
+ cast(ExpressionStateImpl, self),
n_variables=self.n_variables + size,
indices={**self.indices, var: index}
), index