Merge "Resolve Macros when copying templates" into stable/ocata

This commit is contained in:
Jenkins 2017-08-16 18:36:13 +00:00 committed by Gerrit Code Review
commit ac0e7ea1e6
1 changed files with 14 additions and 0 deletions

View File

@ -182,6 +182,20 @@ class Macro(Function):
"""
return dep_attrs(self.parsed, resource_name)
def __reduce__(self):
"""Return a representation of the macro result suitable for pickling.
This allows the copy module (which works by pickling and then
unpickling objects) to copy a template. Functions in the copy will
return to their original (JSON) form (i.e. a single-element map).
Unlike other functions, macros are *not* preserved during a copy. The
the processed (but unparsed) output is returned in their place.
"""
if isinstance(self.parsed, Function):
return self.parsed.__reduce__()
return type(self.parsed), (self.parsed,)
def _repr_result(self):
return repr(self.parsed)