Merge "Avoid circular references in Macro class"

This commit is contained in:
Jenkins 2016-09-15 06:30:06 +00:00 committed by Gerrit Code Review
commit 9730600c08
1 changed files with 11 additions and 1 deletions

View File

@ -140,9 +140,19 @@ class Macro(Function):
def __init__(self, stack, fn_name, raw_args, parse_func, template):
"""Initialise with the argument syntax tree and parser function."""
super(Macro, self).__init__(stack, fn_name, raw_args)
self.template = template
self._tmplref = weakref.ref(template) if template is not None else None
self.parsed = self.parse_args(parse_func)
@property
def template(self):
ref = self._tmplref
if ref is None:
return None
tmpl = ref()
assert tmpl is not None, "Need a reference to the Template object"
return tmpl
@abc.abstractmethod
def parse_args(self, parse_func):
"""Parse the macro using the supplied parsing function.