From dd2be4c1d109a03514ae3324b6f59d23ba8fe3ee Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 28 Sep 2024 14:08:50 +0100 Subject: [PATCH] python 3.8 fixes --- pyzx/graph/base.py | 2 +- pyzx/graph/jsonparser.py | 4 ++-- pyzx/graph/scalar.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pyzx/graph/base.py b/pyzx/graph/base.py index 537f0885..9df1a9e3 100644 --- a/pyzx/graph/base.py +++ b/pyzx/graph/base.py @@ -480,7 +480,7 @@ def to_matrix(self,preserve_scalar:bool=True) -> np.ndarray: """Returns a representation of the graph as a matrix using :func:`~pyzx.tensor.tensorfy`""" return tensor_to_matrix(tensorfy(self, preserve_scalar), self.num_inputs(), self.num_outputs()) - def to_dict(self, include_scalar:bool=True) -> dict[str, Any]: + def to_dict(self, include_scalar:bool=True) -> Dict[str, Any]: """Returns a json representation of the graph that follows the Quantomatic .qgraph format. Convert back into a graph using :meth:`from_json`.""" from .jsonparser import graph_to_dict diff --git a/pyzx/graph/jsonparser.py b/pyzx/graph/jsonparser.py index d3955893..78038cd0 100644 --- a/pyzx/graph/jsonparser.py +++ b/pyzx/graph/jsonparser.py @@ -71,7 +71,7 @@ def _new_var(name: str) -> Poly: except Exception as e: raise ValueError(e) -def json_to_graph(js: str|dict[str,Any], backend:Optional[str]=None) -> BaseGraph: +def json_to_graph(js: Union[str,dict[str,Any]], backend:Optional[str]=None) -> BaseGraph: """Converts the json representation of a .qgraph Quantomatic graph into a pyzx graph. If JSON is given as a string, parse it first.""" if isinstance(js, str): @@ -181,7 +181,7 @@ def json_to_graph(js: str|dict[str,Any], backend:Optional[str]=None) -> BaseGrap return g -def graph_to_dict(g: BaseGraph[VT,ET], include_scalar: bool=True) -> dict[str, Any]: +def graph_to_dict(g: BaseGraph[VT,ET], include_scalar: bool=True) -> Dict[str, Any]: """Converts a PyZX graph into Python dict for JSON output. If include_scalar is set to True (the default), then this includes the value of g.scalar with the json, which will also be loaded by the ``from_json`` method.""" diff --git a/pyzx/graph/scalar.py b/pyzx/graph/scalar.py index ee998388..7a803961 100644 --- a/pyzx/graph/scalar.py +++ b/pyzx/graph/scalar.py @@ -20,7 +20,7 @@ import cmath import copy from fractions import Fraction -from typing import List, Any +from typing import Dict, List, Any, Union import json from ..utils import FloatInt, FractionLike @@ -178,7 +178,7 @@ def to_unicode(self) -> str: s += "{:d}/{:d}π)".format(phase.numerator,phase.denominator) return s - def to_dict(self) -> dict[str, Any]: + def to_dict(self) -> Dict[str, Any]: d = {"power2": self.power2, "phase": str(self.phase)} if abs(self.floatfactor - 1) > 0.00001: d["floatfactor"] = self.floatfactor @@ -194,7 +194,7 @@ def to_json(self) -> str: return json.dumps(self.to_dict()) @classmethod - def from_json(cls, s: str|dict[str,Any]) -> 'Scalar': + def from_json(cls, s: Union[str,dict[str,Any]]) -> 'Scalar': if isinstance(s, str): d = json.loads(s) else: