[pygobject] docs: Replace usage of functools.wraps with a custom version



commit aeccdaddf32dc7b48a79a1cd95a421a26895c9b2
Author: Simon Feltman <sfeltman src gnome org>
Date:   Tue Dec 31 21:15:27 2013 -0800

    docs: Replace usage of functools.wraps with a custom version
    
    Using functools.wraps in overrides would cause docstring evaluation which
    can hurt performance during overrides loading. Add custom wraps decorator
    which only copies __name__ and __module__ attributes. Remove function
    wrapping used within gi.overrides.overridefunc because the wrapping was not
    doing anything, this preserves __doc__ ability without causing an eval at
    load time.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=697356

 gi/overrides/GObject.py  |    3 +--
 gi/overrides/__init__.py |   21 ++++++++++++---------
 2 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 2187ce5..147a452 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -23,7 +23,6 @@
 
 import sys
 import warnings
-import functools
 from collections import namedtuple
 
 import gi.overrides
@@ -515,7 +514,7 @@ def _signalmethod(func):
     # Function wrapper for signal functions used as instance methods.
     # This is needed when the signal functions come directly from GI.
     # (they are not already wrapped)
-    @functools.wraps(func)
+    @gi.overrides.wraps(func)
     def meth(*args, **kwargs):
         return func(*args, **kwargs)
     return meth
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index 3406622..9e7a0f1 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -1,6 +1,5 @@
 import types
 import warnings
-import functools
 
 from gi import PyGIDeprecationWarning
 from gi._gi import CallableInfo
@@ -15,6 +14,14 @@ __path__ = extend_path(__path__, __name__)
 registry = None
 
 
+def wraps(wrapped):
+    def assign(wrapper):
+        wrapper.__name__ = wrapped.__name__
+        wrapper.__module__ = wrapped.__module__
+        return wrapper
+    return assign
+
+
 class _Registry(dict):
     def __setitem__(self, key, value):
         '''We do checks here to make sure only submodules of the override
@@ -61,12 +68,8 @@ class overridefunc(object):
         self.module = modules[module_name]._introspection_module
 
     def __call__(self, func):
-        def wrapper(*args, **kwargs):
-            return func(*args, **kwargs)
-        wrapper.__name__ = func.__name__
-        wrapper.__doc__ = func.__doc__
-        setattr(self.module, func.__name__, wrapper)
-        return wrapper
+        setattr(self.module, func.__name__, func)
+        return func
 
 registry = _Registry()
 
@@ -82,7 +85,7 @@ def override(type_):
 
 def deprecated(fn, replacement):
     '''Decorator for marking methods and classes as deprecated'''
-    @functools.wraps(fn)
+    @wraps(fn)
     def wrapped(*args, **kwargs):
         warnings.warn('%s is deprecated; use %s instead' % (fn.__name__, replacement),
                       PyGIDeprecationWarning, stacklevel=2)
@@ -185,7 +188,7 @@ def strip_boolean_result(method, exc_type=None, exc_str=None, fail_ret=None):
     several out arguments. Translate such a method to return the out arguments
     on success and None on failure.
     '''
-    @functools.wraps(method)
+    @wraps(method)
     def wrapped(*args, **kwargs):
         ret = method(*args, **kwargs)
         if ret[0]:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]