`parse` understands that strings are not macros (#315)

pull/329/head
Tobi 3 years ago committed by GitHub
parent 216b9d730d
commit fcfc58287c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -421,6 +421,12 @@ def parse(macro, context=None, return_errors=False):
try:
macro_object = _parse_recurse(macro, context)
if not isinstance(macro_object, Macro):
# someone put a single parameter like a string into this function, and
# it was most likely returned without modification. Not a macro
raise ValueError("The provided code was not a macro")
return macro_object if not return_errors else None
except Exception as error:
logger.error('Failed to parse macro "%s": %s', macro, error.__repr__())

@ -360,6 +360,10 @@ class TestMacros(MacroTestBase):
self.assertIsNone(parse("r(a, k(b))", self.context))
self.assertIsNone(parse("m(a, b)", self.context))
# passing a string parameter. This is not a macro, even though
# it might look like it without the string quotes.
self.assertIsNone(parse('"m(a, b)"', self.context))
async def test_0(self):
macro = parse("k(1)", self.context)
one_code = system_mapping.get("1")

Loading…
Cancel
Save