diff --git a/symbolite/abstract/symbol.py b/symbolite/abstract/symbol.py index 27770ca..e7f4b3a 100644 --- a/symbolite/abstract/symbol.py +++ b/symbolite/abstract/symbol.py @@ -120,9 +120,11 @@ def __getitem__(self, key: Any) -> Self: return getitem(self, key) # Emulating attribute - def __getattr__(self, key: Any) -> Self: + def __getattr__(self, key: str) -> Self: """Defines behavior for when an item is accessed, using the notation self.key""" + if key.startswith("__"): + raise AttributeError(key) return symgetattr(self, key) # Normal arithmetic operators diff --git a/symbolite/testsuite/test_serialize.py b/symbolite/testsuite/test_serialize.py new file mode 100644 index 0000000..8b9ddc4 --- /dev/null +++ b/symbolite/testsuite/test_serialize.py @@ -0,0 +1,13 @@ +import pickle + +from pytest import mark + +from .. import Scalar, Symbol, Vector + + +@mark.parametrize("cls", [Scalar, Symbol, Vector]) +def test_pickle(cls): + obj = cls() + dump = pickle.dumps(obj) + load = pickle.loads(dump) + assert load == obj