diff --git a/telingo/theory/body.py b/telingo/theory/body.py index ab3de70..bce87ee 100644 --- a/telingo/theory/body.py +++ b/telingo/theory/body.py @@ -4,6 +4,7 @@ """ import clingo as _clingo +from telingo.util import getattr_ from .formula import * @@ -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: diff --git a/telingo/util.py b/telingo/util.py new file mode 100644 index 0000000..ea4179d --- /dev/null +++ b/telingo/util.py @@ -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))))