Skip to content

Commit

Permalink
Merge branch 'noetic-devel' into ros2
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Jan 25, 2024
2 parents ce628cc + a746802 commit 167f673
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions test/test_xacro.py
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,11 @@ def test_yaml_custom_constructors_illegal_expr(self):
</a>'''
self.assertRaises(xacro.XacroException, self.quick_xacro, src.format(file=file))

def test_yaml_hasattr_support(self):
yaml = xacro.load_yaml('settings.yaml')
self.assertTrue(hasattr(yaml, 'arms'))
self.assertFalse(hasattr(yaml, 'this_key_does_not_exist'))

def test_xacro_exist_required(self):
src = '''
<a xmlns:xacro="http://www.ros.org/wiki/xacro">
Expand Down
6 changes: 3 additions & 3 deletions xacro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class YamlDictWrapper(dict):
def __getattr__(self, item):
try:
return YamlListWrapper.wrap(super(YamlDictWrapper, self).__getitem__(item))
except KeyError:
raise XacroException("No such key: '{}'".format(item))
except KeyError: # raise AttributeError instead to support hasattr()
raise AttributeError("The yaml dictionary has no key '{}'".format(item))

__getitem__ = __getattr__

Expand Down Expand Up @@ -193,7 +193,7 @@ def expose(*args, **kwargs):
expose('sorted', 'range', source=__builtins__, ns='python', deprecate_msg=deprecate_msg)
# Expose all builtin symbols into the python namespace. Thus the stay accessible if the global symbol was overriden
expose('list', 'dict', 'map', 'len', 'str', 'float', 'int', 'True', 'False', 'min', 'max', 'round',
'all', 'any', 'complex', 'divmod', 'enumerate', 'filter', 'frozenset', 'hash', 'isinstance', 'issubclass',
'abs', 'all', 'any', 'complex', 'divmod', 'enumerate', 'filter', 'frozenset', 'hash', 'isinstance', 'issubclass',
'ord', 'repr', 'reversed', 'slice', 'set', 'sum', 'tuple', 'type', 'zip', source=__builtins__, ns='python')

# Expose all math symbols and functions into namespace math (and directly for backwards compatibility -- w/o deprecation)
Expand Down

0 comments on commit 167f673

Please sign in to comment.