Skip to content

Commit

Permalink
Merge pull request #717 from vsbogd/fix-python-match
Browse files Browse the repository at this point in the history
Fix exception on matching Python and Rust grounded atoms
  • Loading branch information
Necr0x0Der authored Jun 14, 2024
2 parents cabe90a + ccf8948 commit 9ec96e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python/hyperon/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ def _priv_compare_value_atom(gnd, catom):
"""
if hp.atom_get_metatype(catom) == AtomKind.GROUNDED:
atom = GroundedAtom(catom)
return gnd == atom.get_object()
try:
return gnd == atom.get_object()
except TypeError:
return False
else:
return False

Expand Down
14 changes: 14 additions & 0 deletions python/tests/test_metta.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,17 @@ def test_runner_error(self):
self.assertTrue(False, "Parse error expected")
except RuntimeError as e:
self.assertEqual(e.args[0], 'Unexpected end of expression')

def test_match_with_rust_grounded_atom(self):
program = '''
; True is used as a Python grounded object
(grounded True)
; import! is used as a Rust grounded object which can be
; received from Python
!(match &self (grounded import!) Ok)
'''
runner = MeTTa(env_builder=Environment.test_env())
result = runner.run(program)

self.assertEqual([[]], result)

0 comments on commit 9ec96e2

Please sign in to comment.