Skip to content

Commit fd4ba32

Browse files
committed
Fix the type used for annotation output types
1 parent 7cf287f commit fd4ba32

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Fixed
4646
the documentation.
4747
- Correctly pass the ``-O0`` flag to the CLI when ``optimisation_level`` is set
4848
to zero.
49+
- Set type of MiniZinc annotation output type `ann` to `str` in Python in
50+
accordance with the JSON output format.
4951

5052
0.4.2_ - 2020-11-25
5153
-------------------

src/minizinc/CLI/driver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def to_python_type(mzn_type: dict) -> Type:
4848
pytype = int
4949
elif basetype == "string":
5050
pytype = str
51+
elif basetype == "ann":
52+
pytype = str
5153
else:
5254
warnings.warn(
5355
f"Unable to determine minizinc type `{basetype}` assuming integer type",

tests/test_types.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,19 @@ def test_npint64(self):
220220
self.instance["x"] = numpy.int64(0)
221221
result = self.instance.solve()
222222
assert result.status is Status.SATISFIED
223+
224+
225+
# Enable on MiniZinc 2.6+ (JSON output of annotations is broken before then)
226+
# class TestAnn(InstanceTestCase):
227+
# def test_ann_atom(self):
228+
# self.instance.add_string("ann: x :: add_to_output = promise_total;")
229+
# result = self.instance.solve()
230+
# assert result.status is Status.SATISFIED
231+
# assert result["x"] == "promise_total"
232+
233+
# def test_ann_call(self):
234+
# self.instance.add_string(
235+
# 'ann: x :: add_to_output = expression_name("test");')
236+
# result = self.instance.solve()
237+
# assert result.status is Status.SATISFIED
238+
# assert result["x"] == 'expression_name("test")'

0 commit comments

Comments
 (0)