Skip to content

Commit

Permalink
Merge pull request #414 from vsbogd/more-verbose-error
Browse files Browse the repository at this point in the history
Add clear error about incorrect grounded Python function implementation
  • Loading branch information
Necr0x0Der authored Aug 29, 2023
2 parents d0976e5 + 6b597f2 commit e9cd6e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/hyperonpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ exec_error_t py_execute(const struct gnd_t* _cgnd, const struct atom_vec_t* _arg
}
py::list result = call_execute_on_grounded_atom(pyobj, pytyp, args);
for (py::handle atom: result) {
if (!py::hasattr(atom, "catom")) {
return exec_error_runtime("Grounded operation which is defined using unwrap=False should return atom instead of Python type");
}
atom_vec_push(ret, atom_clone(atom.attr("catom").cast<CAtom>().ptr()));
}
return exec_error_no_err();
Expand Down
10 changes: 10 additions & 0 deletions python/tests/test_atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ def test_interpret(self):
self.assertEqual(interpret(space, E(x2Atom, ValueAtom(1))),
[ValueAtom(2)])

def test_grounded_returns_python_value_unwrap_false(self):
def x2_op(atom):
return [2 * atom.get_object().value]
x2Atom = OperationAtom('*2', x2_op, type_names=["int", "int"], unwrap=False)
expr = E(x2Atom, ValueAtom(1))

space = GroundingSpaceRef()
self.assertEqual(interpret(space, expr),
[E(S('Error'), expr, S('Grounded operation which is defined using unwrap=False should return atom instead of Python type'))])

def test_plan(self):
space = GroundingSpaceRef()
interpreter = Interpreter(space, E(x2Atom, ValueAtom(1)))
Expand Down

0 comments on commit e9cd6e3

Please sign in to comment.