[pygobject] Revert "Drop gi.overrides.overridefunc()"



commit 9ab6e5451aea43ed086c0d26324c4efed24476d7
Author: Martin Pitt <martinpitt gnome org>
Date:   Tue Mar 5 12:04:55 2013 +0100

    Revert "Drop gi.overrides.overridefunc()"
    
    This reverts commit 1dc2bc9f65669417ae1964d70b85f115928b2963. External modules
    like GEdit plugins use @overrides for functions as well, we must not break
    them.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=695199

 gi/overrides/Gtk.py      |    7 ++++---
 gi/overrides/__init__.py |   24 ++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 7873f34..ab09a26 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -1489,11 +1489,12 @@ if Gtk._version != '2.0':
     Menu = override(Menu)
     __all__.append('Menu')
 
+_Gtk_main_quit = Gtk.main_quit
 
-def main_quit(*args):
-    Gtk.main_quit()
 
-__all__.append('main_quit')
+ override(Gtk.main_quit)
+def main_quit(*args):
+    _Gtk_main_quit()
 
 stock_lookup = strip_boolean_result(Gtk.stock_lookup)
 __all__.append('stock_lookup')
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index bd3af9e..99cb152 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -1,3 +1,4 @@
+import types
 import warnings
 import functools
 
@@ -48,13 +49,32 @@ class _Registry(dict):
         self[override_class] = override_class
 
 
+class overridefunc(object):
+    '''decorator for overriding a function'''
+    def __init__(self, func):
+        if not hasattr(func, '__info__'):
+            raise TypeError("func must be an gi function")
+        from ..importer import modules
+        module_name = func.__module__.rsplit('.', 1)[-1]
+        self.module = modules[module_name]._introspection_module
+
+    def __call__(self, func):
+        def wrapper(*args, **kwargs):
+            return func(*args, **kwargs)
+        wrapper.__name__ = func.__name__
+        setattr(self.module, func.__name__, wrapper)
+        return wrapper
+
 registry = _Registry()
 
 
 def override(type_):
     '''Decorator for registering an override'''
-    registry.register(type_)
-    return type_
+    if isinstance(type_, types.FunctionType):
+        return overridefunc(type_)
+    else:
+        registry.register(type_)
+        return type_
 
 
 def deprecated(fn, replacement):


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