From 7bd65b805d9a7d91d9054675e3673bc83ecb0521 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 26 Sep 2024 09:07:41 +0100 Subject: [PATCH] scalar from_json --- pyzx/graph/scalar.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyzx/graph/scalar.py b/pyzx/graph/scalar.py index bcea3285..ee998388 100644 --- a/pyzx/graph/scalar.py +++ b/pyzx/graph/scalar.py @@ -194,8 +194,11 @@ def to_json(self) -> str: return json.dumps(self.to_dict()) @classmethod - def from_json(cls, s: str) -> 'Scalar': - d = json.loads(s) + def from_json(cls, s: str|dict[str,Any]) -> 'Scalar': + if isinstance(s, str): + d = json.loads(s) + else: + d = s d["phase"] = Fraction(d["phase"]) if "phasenodes" in d: d["phasenodes"] = [Fraction(p) for p in d["phasenodes"]]