Bug 1264831 - Try to detect decorators declared in the sandbox and add some automatic @wraps. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 14 Apr 2016 14:46:16 +0900
changeset 317139 cc9627a61ab171c0dc58e080a6f004f26107ad0f
parent 317138 69744c3a2c2306b7cb2455c4f2c738a7655603a6
child 317140 6b915bf8df2a3cbf7810d05d910c74372eb2df19
push id9480
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 17:12:58 +0000
treeherdermozilla-aurora@0d6a91c76a9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1264831
milestone48.0a1
Bug 1264831 - Try to detect decorators declared in the sandbox and add some automatic @wraps. r=gps
python/mozbuild/mozbuild/configure/__init__.py
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -492,16 +492,24 @@ class ConfigureSandbox(dict):
             # available there.
             @wraps(template)
             def wrapper(*args, **kwargs):
                 args = [maybe_prepare_function(arg) for arg in args]
                 kwargs = {k: maybe_prepare_function(v)
                           for k, v in kwargs.iteritems()}
                 ret = template(*args, **kwargs)
                 if isfunction(ret):
+                    # We can't expect the sandboxed code to think about all the
+                    # details of implementing decorators, so do some of the
+                    # work for them. If the function takes exactly one function
+                    # as argument and returns a function, it must be a
+                    # decorator, so mark the returned function as wrapping the
+                    # function passed in.
+                    if len(args) == 1 and not kwargs and isfunction(args[0]):
+                        ret = wraps(args[0])(ret)
                     return wrap_template(ret)
                 return ret
             return wrapper
 
         wrapper = wrap_template(template)
         self._templates.add(wrapper)
         return wrapper