Skip to content

Commit

Permalink
python 3.8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
akissinger committed Sep 28, 2024
1 parent 24b9aca commit dd2be4c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyzx/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pyzx/graph/jsonparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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."""
Expand Down
6 changes: 3 additions & 3 deletions pyzx/graph/scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit dd2be4c

Please sign in to comment.