diff --git a/artiq/protocols/pyon.py b/artiq/protocols/pyon.py index b7abfa93a..10b5412aa 100644 --- a/artiq/protocols/pyon.py +++ b/artiq/protocols/pyon.py @@ -35,6 +35,7 @@ _encode_map = { bytes: "bytes", tuple: "tuple", list: "list", + set: "set", dict: "dict", wrapping_int: "number", Fraction: "fraction", @@ -98,6 +99,12 @@ class _Encoder: r += "]" return r + def encode_set(self, x): + r = "{" + r += ", ".join([self.encode(item) for item in x]) + r += "}" + return r + def encode_dict(self, x): r = "{" if not self.pretty or len(x) < 2: @@ -149,9 +156,7 @@ class _Encoder: def encode(x, pretty=False): """Serializes a Python object and returns the corresponding string in - Python syntax. - - """ + Python syntax.""" return _Encoder(pretty).encode(x) @@ -181,9 +186,7 @@ _eval_dict = { def decode(s): """Parses a string in the Python syntax, reconstructs the corresponding - object, and returns it. - - """ + object, and returns it.""" return eval(s, _eval_dict, {}) diff --git a/artiq/test/serialization.py b/artiq/test/serialization.py index 88cf9b18e..9c23481b9 100644 --- a/artiq/test/serialization.py +++ b/artiq/test/serialization.py @@ -10,6 +10,7 @@ from artiq.protocols import pyon _pyon_test_object = { (1, 2): [(3, 4.2), (2, )], Fraction(3, 4): np.linspace(5, 10, 1), + {"testing", "sets"}, "a": np.int8(9), "b": np.int16(-98), "c": np.int32(42), "d": np.int64(-5), "e": np.uint8(8), "f": np.uint16(5), "g": np.uint32(4), "h": np.uint64(9), "x": np.float16(9.0), "y": np.float32(9.0), "z": np.float64(9.0),