summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Feltman <sfeltman@src.gnome.org>2013-09-11 05:05:33 -0700
committerSimon Feltman <sfeltman@src.gnome.org>2013-09-11 05:05:33 -0700
commit59a2964141e963d2961e55d4b84a777927b4f21b (patch)
tree0d179f5a0f51787323221518bf30c44e088b7c7c
parentafa42ab95327da1de0cf86005974cd8ab0d46872 (diff)
downloadpygobject-59a2964141e963d2961e55d4b84a777927b4f21b.tar.gz
Fix GLib.Source sub-classing with initializer args
Add variable args and keyword args to the GLib.Source.__new__ method to support sub-classes which want to implement __init__. https://bugzilla.gnome.org/show_bug.cgi?id=707904
-rw-r--r--gi/overrides/GLib.py2
-rw-r--r--tests/test_source.py11
2 files changed, 12 insertions, 1 deletions
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index 0a4cdb6a..f4b1ef57 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -536,7 +536,7 @@ __all__.append('MainContext')
class Source(GLib.Source):
- def __new__(cls):
+ def __new__(cls, *args, **kwargs):
# use our custom pyg_source_new() here as g_source_new() is not
# bindable
source = source_new()
diff --git a/tests/test_source.py b/tests/test_source.py
index 5b3b51ba..d0e28e4e 100644
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -214,6 +214,17 @@ class TestSource(unittest.TestCase):
del source
self.assertTrue(self.finalized)
+ def test_extra_init_args(self):
+ class SourceWithInitArgs(GLib.Source):
+ def __init__(self, arg, kwarg=None):
+ super(SourceWithInitArgs, self).__init__()
+ self.arg = arg
+ self.kwarg = kwarg
+
+ source = SourceWithInitArgs(1, kwarg=2)
+ self.assertEqual(source.arg, 1)
+ self.assertEqual(source.kwarg, 2)
+
class TestUserData(unittest.TestCase):
def test_idle_no_data(self):