From 59a2964141e963d2961e55d4b84a777927b4f21b Mon Sep 17 00:00:00 2001 From: Simon Feltman Date: Wed, 11 Sep 2013 05:05:33 -0700 Subject: 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 --- gi/overrides/GLib.py | 2 +- tests/test_source.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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): -- cgit v1.2.1