Require prefix for the attach tag.

For `mjs_attachFrame` and `mjs_attachBody`, require either a prefix or suffix.

It is tempting for users to not use a prefix (see #2162), but this causes issues. For example, it creates a duplicate "main" default class in the parent as a child of the already existing "main" default.

PiperOrigin-RevId: 688535755
Change-Id: I653181ca35943f1e4eb89c70fca8b5289818324e
This commit is contained in:
Alessio Quaglino
2024-10-22 07:07:33 -07:00
committed by Copybara-Service
parent 94e9912d28
commit bfa78614c8
5 changed files with 23 additions and 15 deletions
+2 -2
View File
@@ -850,7 +850,7 @@ class SpecsTest(absltest.TestCase):
body = parent.worldbody.add_body()
frame = child.worldbody.add_frame()
with self.assertRaises(ValueError) as cm:
body.attach_frame(frame, '', '')
body.attach_frame(frame, '_', '')
self.assertEqual(
str(cm.exception),
'Error: cannot attach mjSpecs with incompatible compiler/angle'
@@ -862,7 +862,7 @@ class SpecsTest(absltest.TestCase):
parent = mujoco.MjSpec()
site = parent.worldbody.add_site(pos=[1, 2, 3])
body = child.worldbody.add_body()
self.assertIsNotNone(site.attach(body, '', ''))
self.assertIsNotNone(site.attach(body, '_', ''))
model = parent.compile()
np.testing.assert_array_equal(model.body_pos[1], [1, 2, 3])