[pygobject: 1/2] overrides: Use functools.wraps instead of custom version; fixes #271
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject: 1/2] overrides: Use functools.wraps instead of custom version; fixes #271
- Date: Sat, 27 Oct 2018 09:08:51 +0000 (UTC)
commit cdc17ec6aa3e0fcc23c63e67631b2ab60e82c001
Author: Kai Willadsen <kai willadsen gmail com>
Date: Thu Oct 25 06:50:27 2018 +1000
overrides: Use functools.wraps instead of custom version; fixes #271
Other than familiarity, the main benefit here is mirroring more
attributes from the wrapped function, and the addition of a __wrapped__
attribute to the wrapper, to help with introspection.
gi/overrides/GObject.py | 4 ++--
gi/overrides/__init__.py | 13 +++----------
2 files changed, 5 insertions(+), 12 deletions(-)
---
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 68ba6d50..4a6102d6 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -21,10 +21,10 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
+import functools
import warnings
from collections import namedtuple
-import gi.overrides
import gi.module
from gi.overrides import override, deprecated_attr
from gi.repository import GLib
@@ -549,7 +549,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)
- @gi.overrides.wraps(func)
+ @functools.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 e262b6c1..1572d251 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -1,3 +1,4 @@
+import functools
import types
import warnings
import importlib
@@ -19,14 +20,6 @@ __path__ = extend_path(__path__, __name__)
_deprecated_attrs = {}
-def wraps(wrapped):
- def assign(wrapper):
- wrapper.__name__ = wrapped.__name__
- wrapper.__module__ = wrapped.__module__
- return wrapper
- return assign
-
-
class OverridesProxyModule(types.ModuleType):
"""Wraps a introspection module and contains all overrides"""
@@ -216,7 +209,7 @@ overridefunc = override
def deprecated(fn, replacement):
"""Decorator for marking methods and classes as deprecated"""
- @wraps(fn)
+ @functools.wraps(fn)
def wrapped(*args, **kwargs):
warnings.warn('%s is deprecated; use %s instead' % (fn.__name__, replacement),
PyGIDeprecationWarning, stacklevel=2)
@@ -335,7 +328,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.
"""
- @wraps(method)
+ @functools.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]