Bug 1264831 - Try to detect decorators declared in the sandbox and add some automatic @wraps. r?gps draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 14 Apr 2016 14:46:16 +0900
changeset 351822 f614307bc205ad279bd8370e1954736b6f75002e
parent 351821 b9da0ecf3545d90f79ad87292ae62012045c6e3d
child 351823 543ee065efc0ee7dcccbf94c1e6bd032ace2af12
push id15531
push userbmo:mh+mozilla@glandium.org
push dateFri, 15 Apr 2016 02:18:00 +0000
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