Merge "Avoid circular references in Macro class"
This commit is contained in:
commit
9730600c08
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue