mirror of
https://github.com/sezanzeb/input-remapper
synced 2024-11-18 03:25:52 +00:00
parse
understands that strings are not macros (#315)
This commit is contained in:
parent
216b9d730d
commit
fcfc58287c
@ -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…
Reference in New Issue
Block a user