Skip to content

Commit

Permalink
make compatible with clingo 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rkaminsk committed Aug 20, 2019
1 parent aef864f commit 87b26c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion telingo/theory/body.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import clingo as _clingo
from telingo.util import getattr_

from .formula import *

Expand Down Expand Up @@ -456,7 +457,9 @@ def do_translate(self, ctx, step, data):
data.done = True
else:
data.literal = ctx.backend.add_atom()
ctx.backend.add_external(data.literal, _clingo.TruthValue._True if self.__weak else _clingo.TruthValue._False)
true = getattr_(_clingo.TruthValue, "_True", "True_", "True")
false = getattr_(_clingo.TruthValue, "_False", "False_", "False")
ctx.backend.add_external(data.literal, true if self.__weak else false)
ctx.add_todo(self, step)
data.done = False
elif not data.done:
Expand Down
15 changes: 15 additions & 0 deletions telingo/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
This module contains simple helper functions.
"""

def getattr_(obj, *attrs):
"""
Returns the first attribute of the given object that is available.
"""
for attr in attrs:
if hasattr(obj, attr):
return getattr(obj, attr)
raise AttributeError(
'{} does not have any of the attributes {}'.format(
obj.__class__.name,
','.join(('"{}"'.format(attr) for attr in attrs))))

0 comments on commit 87b26c9

Please sign in to comment.