From 0e41bc2970d34b3df3c820c3487af9a800eae2ae Mon Sep 17 00:00:00 2001 From: Hendrik Bierlee Date: Wed, 18 Oct 2023 11:51:39 +1100 Subject: [PATCH 1/2] Remove set to range optimization Apparently, ruamel cannot easily parse YAML containing python ranges. A better optimization is to make our own RangeList set representation in the future. --- src/minizinc/json.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/minizinc/json.py b/src/minizinc/json.py index 9886118..7c1f4cd 100644 --- a/src/minizinc/json.py +++ b/src/minizinc/json.py @@ -57,10 +57,6 @@ def transform_enum_object(self, obj): def mzn_object_hook(self, obj): if isinstance(obj, dict): if len(obj) == 1 and "set" in obj: - if len(obj["set"]) == 1 and isinstance(obj["set"][0], list): - assert len(obj["set"][0]) == 2 - return range(obj["set"][0][0], obj["set"][0][1] + 1) - li = [] for item in obj["set"]: if isinstance(item, list): From da1b6d4c96d2cd64a97e7a357d57395b613c9e5e Mon Sep 17 00:00:00 2001 From: Hendrik Bierlee Date: Wed, 18 Oct 2023 12:02:08 +1100 Subject: [PATCH 2/2] Fix and rename range/set test --- tests/test_types.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_types.py b/tests/test_types.py index 4d1dda1..c8127af 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -152,7 +152,7 @@ def test_non_ascii(self): class TestSets(InstanceTestCase): - def test_ranges(self): + def test_sets(self): self.instance.add_string( """ var set of 0..10: s; @@ -163,8 +163,8 @@ def test_ranges(self): self.instance["s1"] = range(1, 4) result = self.instance.solve() - assert isinstance(result["s"], range) - assert result["s"] == range(1, 4) + assert isinstance(result["s"], set) + assert result["s"] == set(range(1, 4)) class TestString(InstanceTestCase):