Bug 1670168 - Fix configure lint error when a template uses an undefined variable. r=firefox-build-system-reviewers,rstewart DONTBUILD

Differential Revision: https://phabricator.services.mozilla.com/D93057
This commit is contained in:
Mike Hommey
2020-10-09 16:25:25 +00:00
parent f73d9ffd19
commit ca614cbf6f
2 changed files with 22 additions and 1 deletions

View File

@@ -312,6 +312,9 @@ class LintSandbox(ConfigureSandbox):
# Raise the same kind of error as what would happen during
# execution.
e = NameError("global name '{}' is not defined".format(instr.argval))
self._raise_from(e, func, instr.starts_line - func.__code__.co_firstlineno)
if instr.starts_line is None:
self._raise_from(e, func)
else:
self._raise_from(e, func, instr.starts_line - code.co_firstlineno)
return wrapped

View File

@@ -397,6 +397,24 @@ class TestLint(unittest.TestCase):
self.assertEquals(str(e.exception),
"global name 'unknown' is not defined")
# Ideally, this would raise on line 4, where `unknown` is used, but
# python disassembly doesn't give use the information.
with self.assertRaisesFromLine(NameError, 2) as e:
with self.moz_configure('''
@template
def tmpl():
@depends(unknown)
def foo(value):
if value:
return True
return foo
tmpl()
'''):
self.lint_test()
self.assertEquals(str(e.exception),
"global name 'unknown' is not defined")
if __name__ == '__main__':
main()