From ccf8948f80b1f38e372d78373103518e4c00c40f Mon Sep 17 00:00:00 2001 From: Vitaly Bogdanov Date: Fri, 14 Jun 2024 13:15:54 +0300 Subject: [PATCH] Fix exception on matching Python and Rust grounded atoms --- python/hyperon/atoms.py | 5 ++++- python/tests/test_metta.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/python/hyperon/atoms.py b/python/hyperon/atoms.py index b808edb74..2941b8b3f 100644 --- a/python/hyperon/atoms.py +++ b/python/hyperon/atoms.py @@ -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 diff --git a/python/tests/test_metta.py b/python/tests/test_metta.py index 2294d0ac7..d7c0e64ae 100644 --- a/python/tests/test_metta.py +++ b/python/tests/test_metta.py @@ -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) +